IMPORT_FOREIGN_SCHEMA(7pg17)

πŸ“¦ version 17.11, in opensuse-leap 16.0

πŸ’– 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