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 ๐ฅ
CREATE FOREIGN TABLE(CREATE_FOREIGN_TABLE(7))CREATE SERVER(CREATE_SERVER(7))
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 ๐๐งโจ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms