IMPORT_FOREIGN_SCHEMA(7)

๐Ÿ’– IMPORT_FOREIGN_SCHEMA ๐Ÿ’–

okay bestie, sit down, hydrate, and let me tell you about IMPORT FOREIGN SCHEMA โ€” it's a PostgreSQL thing, it lives in the PostgreSQL 18.6 docs, and honestly? it's giving โœจeffortlessโœจ. It imports table definitions from a foreign server. No cap. ๐Ÿฆ‹


โœจ SYNOPSIS โœจ

IMPORT FOREIGN SCHEMA remote_schema
    [ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]
    FROM SERVER server_name
    INTO local_schema
    [ OPTIONS ( option 'value' [, ... ] ) ]

look at her. gorgeous. ๐Ÿ’…


๐ŸŒธ DESCRIPTION ๐ŸŒธ

IMPORT FOREIGN SCHEMA makes foreign tables that represent tables already chillin' on a foreign server. And the new foreign tables? They belong to whoever ran the command โ€” the user issuing the command owns them โ€” and they get created with the correct column definitions and options so they actually match up with the remote tables. like, they match. fr fr. ๐Ÿซถ

So by default, every single table and view that exists in that particular schema on the foreign server gets imported. That's a lot of tables, bestie. But if you want, you can limit the list to a specified subset, or you can exclude specific tables instead. your call, main character. ๐Ÿ‘‘

All the new foreign tables get created in the target schema โ€” and heads up, that schema has to already exist. IMPORT FOREIGN SCHEMA is not out here building schemas for you. ๐Ÿ˜ญ

And to even run IMPORT FOREIGN SCHEMA you need USAGE privilege on the foreign server, plus CREATE privilege on the target schema. both. not one. both. ๐ŸŽ€


๐ŸŽ€ 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 iykyk. ๐ŸŒˆ
  • LIMIT TO ( table_name [, ...] ) โ€” import only the foreign tables matching one of the table names you list. every other table in that foreign schema? ignored. not invited to the party. ๐Ÿ™ˆ
  • EXCEPT ( table_name [, ...] ) โ€” the opposite vibe: exclude the foreign tables you name. everything in the foreign schema gets imported except the ones you listed here. ๐Ÿ’€
  • server_name โ€” the foreign server you're importing from.
  • local_schema โ€” the schema where all the imported foreign tables are gonna be created.
  • OPTIONS ( option 'value' [, ...] ) โ€” options used during the import. which option names and values are allowed? that's specific to each foreign data wrapper, so check yours. โญ

๐Ÿ’– 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 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;

obsessed with how clean that is. ๐Ÿ“


๐Ÿฆ‹ COMPATIBILITY ๐Ÿฆ‹

The IMPORT FOREIGN SCHEMA command conforms to the SQL standard โ€” slay โ€” except that the OPTIONS clause is a PostgreSQL extension. so that one part is our little homegrown thing. ๐ŸŒธ


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ


okay that's the whole page, no notes, ate and left no crumbs. ๐Ÿ‘‘

this was PostgreSQL 18.6, dated 2026, and it's the IMPORT FOREIGN SCHEMA(7) manual page โ€” thanks for reading bestie, go import responsibly ๐Ÿ’œ๐Ÿงšโœจ