Skip to main content
Version: 1.0.16

IMPORT FOREIGN SCHEMA

IMPORT FOREIGN SCHEMA — import table definitions from a foreign server

Synopsis

IMPORT FOREIGN SCHEMA remote_schema

[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]

FROM SERVER server_name

INTO local_schema

[ OPTIONS ( option 'value' [, ...] ) ]

Description

IMPORT FOREIGN SCHEMA creates foreign tables that represent tables existing on a foreign server. The new foreign tables are owned by the user issuing the command and are created with the correct column definitions and options to match the remote tables.

By default, all tables and views existing in a particular schema on the foreign server are imported. Optionally, the list of tables can be limited to a specified subset, or specific tables can be excluded. The new foreign tables are all created in the target schema, which must already exist.

To use IMPORT FOREIGN SCHEMA, the user must have USAGE privilege on the foreign server and CREATE privilege on the target schema.

Parameters

remote_schema

The remote schema from which to import. The specific meaning of a remote schema depends on the foreign data wrapper used.

LIMIT TO ( table_name [, ...] )

Import only foreign tables matching one of the given table names. Other tables in the foreign schema will be ignored.

EXCEPT ( table_name [, ...] )

Exclude the specified foreign tables from the import. All tables existing in the foreign schema except those listed here will be imported.

server_name

The foreign server from which to import.

local_schema

The schema in which the imported foreign tables will be created.

OPTIONS ( option 'value' [, ...] )

Options to be used during the import. The allowed option names and values are specific to each foreign data wrapper.

Examples

# Import table definitions from the remote schema foreign_films on server film_server, creating the foreign tables in the local schema films:

IMPORT FOREIGN SCHEMA foreign_films

FROM SERVER film_server INTO films;

# Same as above, but only import the two tables actors and directors (if they exist):

IMPORT FOREIGN SCHEMA foreign_films LIMIT TO (actors, directors)

FROM SERVER film_server INTO films;

See Also

CREATE FOREIGN TABLE, CREATE SERVER