IMPORT FOREIGN SCHEMA

A DDL command to import table definitions from a foreign server

IMPORT FOREIGN SCHEMA is a DDL command to import foreign table (and view) definitions from a foreign server.

IMPORT FOREIGN SCHEMA was added in PostgreSQL 9.5 (initial commit 59efda3e).

Implementation

The implementation of IMPORT FOREIGN SCHEMA is very much dependent on the individual foreign data wrapper. In particular the settings available via the OPTIONS parameter are specific to each FDW.

Documentation for IMPORT FOREIGN SCHEMA as provided by various FDWs:

Note that some FDWs (e.g. file_fdw) do not support IMPORT FOREIGN SCHEMA, as there is no underlying schema which can be imported.

Change history

The syntax of IMPORT FOREIGN SCHEMA has not changed since it was introduced in PostgreSQL 9.5.

Examples

With postgres_fdw:

IMPORT FOREIGN SCHEMA public
  LIMIT TO (sometable)
  FROM SERVER pg_remote_server
  INTO public;

IMPORT FOREIGN SCHEMA public
  EXCEPT (othertable, thattable)
  FROM SERVER pg_remote_server
  INTO public;

IMPORT FOREIGN SCHEMA public
  EXCEPT (othertable, thattable)
  FROM SERVER pg_remote_server
  INTO public
  OPTIONS (import_not_null 'false');

Categories

DDL, Foreign Data Wrapper (FDW)