IMPORT_FOREIGN_SCHEMA(7pg16)

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

πŸ’– NAME πŸ’–

okay so bestie, this is the IMPORT FOREIGN SCHEMA(7) page, straight out of the PostgreSQL 16.15 Documentation ✨ and the vibe is: IMPORT_FOREIGN_SCHEMA β€” importing 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 πŸ¦‹

So IMPORT FOREIGN SCHEMA creates foreign tables that represent tables that already exist on a foreign server. The new foreign tables get owned by the user issuing the command, and they're created with the correct column definitions and options so they match the remote tables. it's giving "mirror, mirror" πŸ’…

By default, all tables and views existing in a particular schema on the foreign server get imported. But you can optionally limit the list of tables to a specified subset, or exclude specific tables. The new foreign tables are all created in the target schema, which must already exist β€” no auto-creating it for you, sorry bestie πŸ™ˆ

To use IMPORT FOREIGN SCHEMA, the user must have USAGE privilege on the foreign server, plus CREATE privilege on the target schema. both. no shortcuts πŸ”₯


✨ PARAMETERS ✨

  • remote_schema β€” the remote schema you're importing from. what a "remote schema" actually means depends on the foreign data wrapper in use, so like... iykyk 🧚
  • LIMIT TO ( table_name [, ...] ) β€” import only the foreign tables matching one of the given table names. every other table hanging out in the foreign schema gets ignored. cherry-picking, but make it SQL πŸ“
  • EXCEPT ( table_name [, ...] ) β€” the opposite energy: exclude the specified foreign tables from the import. all tables in the foreign schema get imported except the ones you list here. not those ones, bestie πŸ’€
  • server_name β€” the foreign server you're importing from. that's the one πŸ‘‘
  • local_schema β€” the schema where the imported foreign tables get created. it has to exist already, remember 🌈
  • OPTIONS ( option 'value' [, ...] ) β€” options used during the import. the allowed option names and values are specific to each foreign data wrapper, so check with your wrapper, not with me πŸŽ€

πŸ’œ 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;

Same thing 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;

two little examples, both iconic, both literally doing their job ⭐


🌺 COMPATIBILITY 🌺

The IMPORT FOREIGN SCHEMA command conforms to the SQL standard β€” with one tiny caveat: the OPTIONS clause is a PostgreSQL extension. so yeah, standard-ish, but not 100% standard. ngl it ate though πŸ’…


πŸ’« SEE ALSO πŸ’«

go read those next, bestie, they're the prequels 🫢


and that's the whole page!! πŸ’– brought to you by PostgreSQL 16.15, dated 2026, filed under IMPORT FOREIGN SCHEMA(7) β€” slay, periodt, go import some schemas πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from