IMPORT_FOREIGN_SCHEMA(7pg17)
π NAME π
okay bestie, meet IMPORT_FOREIGN_SCHEMA(7pg17) β the command that imports table definitions from a foreign server. That's the whole vibe: remote tables, but make them show up as foreign tables for you. β¨
π οΈ SYNOPSIS π οΈ
IMPORT FOREIGN SCHEMA remote_schema
[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]
FROM SERVER server_name
INTO local_schema
[ OPTIONS ( option 'value' [, ... ] ) ]
πΈ DESCRIPTION πΈ
okay so here's what it does: IMPORT FOREIGN SCHEMA creates foreign tables that represent tables already existing on a foreign server. The new foreign tables are owned by the user issuing the command, and they're created with the correct column definitions and options to match the remote tables. no cap. π
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, and that target schema must already exist β it will not make it for you, bestie. π«Ά
To use IMPORT FOREIGN SCHEMA, the user must have USAGE privilege on the foreign server, as well as CREATE privilege on the target schema. Both. Periodt. π
π PARAMETERS π
remote_schemaβ the remote schema to import from. What a remote schema means specifically depends on the foreign data wrapper in use. Very wrapper-specific, iykyk. π¦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. Very picky, very slay. β¨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. not me excluding them from the group chat πserver_nameβ the foreign server to import from.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 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. that's the one little extra sparkle π«
π¦ SEE ALSO π¦
Also go see CREATE FOREIGN TABLE (CREATE_FOREIGN_TABLE(7)), CREATE SERVER (CREATE_SERVER(7)). iconic references, honestly π
and that's the tea π΅ β PostgreSQL 17.11, 2026, IMPORT FOREIGN SCHEMA(7). mwah π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms