Overview

This code block demonstrates how to create a foreign table over the local file system. Note that this only works for files on the same machine as the Postgres instance.

CREATE FOREIGN DATA WRAPPER <wrapper_name>
HANDLER local_file_fdw_handler
VALIDATOR local_file_fdw_validator;

CREATE SERVER <server_name>
FOREIGN DATA WRAPPER <wrapper_name>;

-- Replace the dummy schema with the actual schema
CREATE FOREIGN TABLE <table_name> ("x" INT)
SERVER <server_name>
OPTIONS (path '<path>', extension '<extension>');
wrapper_name
required

Foreign data wrapper name. Can be any string.

server_name
required

Foreign server name. Can be any string.

table_name
required

Foreign table name. Can be any string.

Options for CREATE FOREIGN TABLE

path
required

Must start with file:/// and point to the location of your file. The path should end in a / if it points to a directory of partitioned Parquet files.

extension
required

One of avro, csv, json, and parquet.

format

For now, only delta is supported for Delta Lake (Iceberg is coming soon). If omitted, no table format is assumed.