IMPORT FOREIGN SCHEMA
import table definitions from a foreign server
English manual coverage begins with PostgreSQL 6.4. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- anchor
- SQL-IMPORTFOREIGNSCHEMA
- file
- sql-importforeignschema.html
- lang
- en
- name
- IMPORT FOREIGN SCHEMA
- purpose
- import table definitions from a foreign server
- purpose zh
- 从一个外部服务器导入表定义
- sections same as
- Unknown
- slug
- 18
- synopsis text
- IMPORT FOREIGN SCHEMA remote_schema [ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ] FROM SERVER server_name INTO local_schema [ OPTIONS ( option 'value' [, ... ] ) ]
Syntax
IMPORT FOREIGN SCHEMA remote_schema
[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]
FROM SERVER server_name
INTO local_schema
[ OPTIONS ( option 'value' [, ... ] ) ]Syntax diagrams
Read left to right. Branches are choices, bypasses are optional, loops repeat. Select an underlined parameter to open its rule.
Definition PG 18
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 will be 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, as well as CREATE privilege on the target schema.
Parameters
remote_schemaThe remote schema to import from. The specific meaning of a remote schema depends on the foreign data wrapper in use.
LIMIT TO (table_name[, ...] )Import only foreign tables matching one of the given table names. Other tables existing in the foreign schema will be ignored.
EXCEPT (table_name[, ...] )Exclude specified foreign tables from the import. All tables existing in the foreign schema will be imported except the ones listed here.
server_nameThe foreign server to import from.
local_schemaThe 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 a remote schema foreign_films on server film_server, creating the foreign tables in local schema films:
IMPORT FOREIGN SCHEMA foreign_films
FROM SERVER film_server INTO films;
As above, but import only the two tables actors and directors (if they exist):
IMPORT FOREIGN SCHEMA foreign_films LIMIT TO (actors, directors)
FROM SERVER film_server INTO films;
Compatibility
The IMPORT FOREIGN SCHEMA command conforms to the SQL standard, except that the OPTIONS clause is a PostgreSQL extension.
See Also
CREATE FOREIGN TABLE, CREATE SERVERCompare versions
Complete source facts
synopsis html
IMPORT FOREIGN SCHEMA <em class="replaceable"><code>remote_schema</code></em>
[ { LIMIT TO | EXCEPT } ( <em class="replaceable"><code>table_name</code></em> [, ...] ) ]
FROM SERVER <em class="replaceable"><code>server_name</code></em>
INTO <em class="replaceable"><code>local_schema</code></em>
[ OPTIONS ( <em class="replaceable"><code>option</code></em> '<em class="replaceable"><code>value</code></em>' [, ... ] ) ]Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · wiki-repair-20261023:5f93a7a0226f8e7fa258a44177afae720e38a1de0662a3602b8a5d979ec6bc01
Text language: en · wiki-repair-20261023:5f93a7a0226f8e7fa258a44177afae720e38a1de0662a3602b8a5d979ec6bc01