{"Entry":{"collection":"sql","key":"import-foreign-schema","name":"IMPORT FOREIGN SCHEMA","aliases":["importforeignschema"],"metadata":{"aliases":["importforeignschema"],"changed_in":[],"changes":[{"from":"9.4","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"9.5"}],"content_hash":"9c181d74960989bb7582a2a3b5f8a080b55b2c81cc12000fcc9d47a4fd662ca5","derived_content_hash":"f5cad60acbb83fb3d18c7366be70d6ae46a9fb9c5a34e6551dc7e2fe493b10b9","editorial":{},"first_version":"9.5","group":"foreign","imported_at":"2026-09-30T17:43:38.731483+08:00","last_version":"20","name":"IMPORT FOREIGN SCHEMA","object":"FOREIGN SCHEMA","position":9003,"present_in":["9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"purpose":"import table definitions from a foreign server","purpose_zh":"","related":["create-foreign-table","create-server"],"repair_provenance":{"original_source_revision":"a709ab85","receipt_sha256":"c85dc81f5de20a3a7d00773eff97650c95551e1251011ddb4e2fe51fc0c0083d","repair":"wiki-repair-20261023"},"slug":"import-foreign-schema","source_rev":"wiki-repair-20261023:5f93a7a0226f8e7fa258a44177afae720e38a1de0662a3602b8a5d979ec6bc01","synopsis":"IMPORT FOREIGN SCHEMA remote_schema\n[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]\nFROM SERVER server_name\nINTO local_schema\n[ OPTIONS ( option 'value' [, ... ] ) ]","verb":"IMPORT"}},"Definition":{"Collection":"sql","Key":"import-foreign-schema","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"import-foreign-schema","SourceRevision":"wiki-repair-20261023:5f93a7a0226f8e7fa258a44177afae720e38a1de0662a3602b8a5d979ec6bc01","Facts":{"anchor":"SQL-IMPORTFOREIGNSCHEMA","description_zh":"从一个外部服务器导入表定义","description_zh_html":"\u003cpre\u003eIMPORT FOREIGN SCHEMA remote_schema\n[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]\nFROM SERVER server_name\nINTO local_schema\n[ OPTIONS ( option \u0026#x27;value\u0026#x27; [, ... ] ) ]\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e 创建外部表，用来表示存在于外部服务器上的表。新的外部表将归发出该命令的用户所有，并使用与远程表相匹配的正确列定义和选项创建。\n  \u003c/p\u003e\u003cp\u003e\n   默认情况下，外部服务器上某个特定模式中的所有表和视图都会被导入。也可以把待导入表的列表限制为指定的子集，或者排除某些特定表。新的外部表都会创建在目标模式中，该模式必须已经存在。\n  \u003c/p\u003e\u003cp\u003e\n   要使用 \u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e，用户必须在外部服务器上拥有 \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e 权限，并在目标模式上拥有 \u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e 权限。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\u003c/h2\u003e\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eremote_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      要从中导入的远程模式。远程模式的具体含义取决于所使用的外部数据包装器。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eLIMIT TO ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      只导入名称与给定表名之一匹配的外部表。远程模式中的其他表将被忽略。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eEXCEPT ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      将指定的外部表排除在导入之外。除这里列出的表外，远程模式中的其他表都会被导入。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      要从中导入的外部服务器。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003elocal_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      将在其中创建所导入外部表的模式。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eOPTIONS ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e '\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e' [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      导入期间要使用的选项。允许的选项名和值取决于各个外部数据包装器。\n     \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e\n   从服务器 \u003ccode class=\"structname\"\u003efilm_server\u003c/code\u003e 上的远程模式 \u003ccode class=\"structname\"\u003eforeign_films\u003c/code\u003e 导入表定义，并在本地模式 \u003ccode class=\"structname\"\u003efilms\u003c/code\u003e 中创建这些外部表：\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nIMPORT FOREIGN SCHEMA foreign_films\n    FROM SERVER film_server INTO films;\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   与上例相同，但只导入 \u003ccode class=\"structname\"\u003eactors\u003c/code\u003e 和 \u003ccode class=\"literal\"\u003edirectors\u003c/code\u003e 这两个表（如果它们存在）：\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nIMPORT FOREIGN SCHEMA foreign_films LIMIT TO (actors, directors)\n    FROM SERVER film_server INTO films;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e 命令符合 \u003cacronym class=\"acronym\"\u003eSQL\u003c/acronym\u003e 标准，但 \u003ccode class=\"literal\"\u003eOPTIONS\u003c/code\u003e 子句是 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 扩展。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/zh/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-createserver.html\" title=\"CREATE SERVER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","file":"sql-importforeignschema.html","lang":"en","name":"IMPORT FOREIGN SCHEMA","purpose":"import table definitions from a foreign server","purpose_zh":"从一个外部服务器导入表定义","related":["create-foreign-table","create-server"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e creates foreign tables that represent tables existing on a foreign server. The new foreign tables will be owned by the user issuing the command and are created with the correct column definitions and options to match the remote tables.\u003c/p\u003e\u003cp\u003eBy 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, which must already exist.\u003c/p\u003e\u003cp\u003eTo use \u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e, the user must have \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e privilege on the foreign server, as well as \u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e privilege on the target schema.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eremote_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe remote schema to import from. The specific meaning of a remote schema depends on the foreign data wrapper in use.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eLIMIT TO ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eImport only foreign tables matching one of the given table names. Other tables existing in the foreign schema will be ignored.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eEXCEPT ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eExclude specified foreign tables from the import. All tables existing in the foreign schema will be imported except the ones listed here.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe foreign server to import from.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003elocal_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe schema in which the imported foreign tables will be created.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eOPTIONS ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e '\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e' [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eOptions to be used during the import. The allowed option names and values are specific to each foreign data wrapper.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eImport table definitions from a remote schema \u003ccode class=\"structname\"\u003eforeign_films\u003c/code\u003e on server \u003ccode class=\"structname\"\u003efilm_server\u003c/code\u003e, creating the foreign tables in local schema \u003ccode class=\"structname\"\u003efilms\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eIMPORT FOREIGN SCHEMA foreign_films\n    FROM SERVER film_server INTO films;\n\u003c/pre\u003e\u003cp\u003eAs above, but import only the two tables \u003ccode class=\"structname\"\u003eactors\u003c/code\u003e and \u003ccode class=\"literal\"\u003edirectors\u003c/code\u003e (if they exist):\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eIMPORT FOREIGN SCHEMA foreign_films LIMIT TO (actors, directors)\n    FROM SERVER film_server INTO films;\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003eThe \u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e command conforms to the \u003cacronym\u003eSQL\u003c/acronym\u003e standard, except that the \u003ccode class=\"literal\"\u003eOPTIONS\u003c/code\u003e clause is a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extension.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/create-foreign-table/?v=18\" title=\"CREATE FOREIGN TABLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-server/?v=18\" title=\"CREATE SERVER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"IMPORT FOREIGN SCHEMA \u003cem class=\"replaceable\"\u003e\u003ccode\u003eremote_schema\u003c/code\u003e\u003c/em\u003e\n    [ { LIMIT TO | EXCEPT } ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] ) ]\n    FROM SERVER \u003cem class=\"replaceable\"\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\n    INTO \u003cem class=\"replaceable\"\u003e\u003ccode\u003elocal_schema\u003c/code\u003e\u003c/em\u003e\n    [ OPTIONS ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e '\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e' [, ... ] ) ]","synopsis_text":"IMPORT FOREIGN SCHEMA remote_schema\n[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]\nFROM SERVER server_name\nINTO local_schema\n[ OPTIONS ( option 'value' [, ... ] ) ]","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/sql-importforeignschema.html","sha256":"5c27a330fc566db81557239b544f186f15fcf79108a344aa1ff6ae406c9b5c64"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"zh_from":"same-version-pgdoc"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"import-foreign-schema","SourceDatabase":"center","Version":"18","Locale":"en","Title":"IMPORT FOREIGN SCHEMA","Summary":"import table definitions from a foreign server","BodyHTML":"\u003cpre\u003eIMPORT FOREIGN SCHEMA remote_schema\n[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]\nFROM SERVER server_name\nINTO local_schema\n[ OPTIONS ( option \u0026#39;value\u0026#39; [, ... ] ) ]\u003c/pre\u003e\u003csection\u003e\u003ch2\u003eDescription\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e creates foreign tables that represent tables existing on a foreign server. The new foreign tables will be owned by the user issuing the command and are created with the correct column definitions and options to match the remote tables.\u003c/p\u003e\u003cp\u003eBy 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, which must already exist.\u003c/p\u003e\u003cp\u003eTo use \u003ccode\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e, the user must have \u003ccode\u003eUSAGE\u003c/code\u003e privilege on the foreign server, as well as \u003ccode\u003eCREATE\u003c/code\u003e privilege on the target schema.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eParameters\u003c/h2\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003eremote_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe remote schema to import from. The specific meaning of a remote schema depends on the foreign data wrapper in use.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eLIMIT TO ( \u003cem\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eImport only foreign tables matching one of the given table names. Other tables existing in the foreign schema will be ignored.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eEXCEPT ( \u003cem\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eExclude specified foreign tables from the import. All tables existing in the foreign schema will be imported except the ones listed here.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe foreign server to import from.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003elocal_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe schema in which the imported foreign tables will be created.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eOPTIONS ( \u003cem\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e \u0026#39;\u003cem\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e\u0026#39; [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eOptions to be used during the import. The allowed option names and values are specific to each foreign data wrapper.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eExamples\u003c/h2\u003e\u003cp\u003eImport table definitions from a remote schema \u003ccode\u003eforeign_films\u003c/code\u003e on server \u003ccode\u003efilm_server\u003c/code\u003e, creating the foreign tables in local schema \u003ccode\u003efilms\u003c/code\u003e:\u003c/p\u003e\u003cpre\u003eIMPORT FOREIGN SCHEMA foreign_films\n    FROM SERVER film_server INTO films;\n\u003c/pre\u003e\u003cp\u003eAs above, but import only the two tables \u003ccode\u003eactors\u003c/code\u003e and \u003ccode\u003edirectors\u003c/code\u003e (if they exist):\u003c/p\u003e\u003cpre\u003eIMPORT FOREIGN SCHEMA foreign_films LIMIT TO (actors, directors)\n    FROM SERVER film_server INTO films;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eCompatibility\u003c/h2\u003e\u003cp\u003eThe \u003ccode\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e command conforms to the \u003cacronym\u003eSQL\u003c/acronym\u003e standard, except that the \u003ccode\u003eOPTIONS\u003c/code\u003e clause is a \u003cspan\u003ePostgreSQL\u003c/span\u003e extension.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/create-foreign-table/?v=18\" title=\"CREATE FOREIGN TABLE\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-server/?v=18\" title=\"CREATE SERVER\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"wiki-repair-20261023:5f93a7a0226f8e7fa258a44177afae720e38a1de0662a3602b8a5d979ec6bc01","ContentHash":"c8c27cc0fd4c05bdbff9f555f0f1145d9c81a40cc3e6928438f6d540ed027a5c","Payload":{"related":["create-foreign-table","create-server"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e creates foreign tables that represent tables existing on a foreign server. The new foreign tables will be owned by the user issuing the command and are created with the correct column definitions and options to match the remote tables.\u003c/p\u003e\u003cp\u003eBy 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, which must already exist.\u003c/p\u003e\u003cp\u003eTo use \u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e, the user must have \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e privilege on the foreign server, as well as \u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e privilege on the target schema.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eremote_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe remote schema to import from. The specific meaning of a remote schema depends on the foreign data wrapper in use.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eLIMIT TO ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eImport only foreign tables matching one of the given table names. Other tables existing in the foreign schema will be ignored.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eEXCEPT ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eExclude specified foreign tables from the import. All tables existing in the foreign schema will be imported except the ones listed here.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe foreign server to import from.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003elocal_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe schema in which the imported foreign tables will be created.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eOPTIONS ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e '\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e' [, ...] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eOptions to be used during the import. The allowed option names and values are specific to each foreign data wrapper.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eImport table definitions from a remote schema \u003ccode class=\"structname\"\u003eforeign_films\u003c/code\u003e on server \u003ccode class=\"structname\"\u003efilm_server\u003c/code\u003e, creating the foreign tables in local schema \u003ccode class=\"structname\"\u003efilms\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eIMPORT FOREIGN SCHEMA foreign_films\n    FROM SERVER film_server INTO films;\n\u003c/pre\u003e\u003cp\u003eAs above, but import only the two tables \u003ccode class=\"structname\"\u003eactors\u003c/code\u003e and \u003ccode class=\"literal\"\u003edirectors\u003c/code\u003e (if they exist):\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eIMPORT FOREIGN SCHEMA foreign_films LIMIT TO (actors, directors)\n    FROM SERVER film_server INTO films;\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003eThe \u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e command conforms to the \u003cacronym\u003eSQL\u003c/acronym\u003e standard, except that the \u003ccode class=\"literal\"\u003eOPTIONS\u003c/code\u003e clause is a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extension.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/create-foreign-table/?v=18\" title=\"CREATE FOREIGN TABLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-server/?v=18\" title=\"CREATE SERVER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","synopsis_html":"IMPORT FOREIGN SCHEMA \u003cem class=\"replaceable\"\u003e\u003ccode\u003eremote_schema\u003c/code\u003e\u003c/em\u003e\n    [ { LIMIT TO | EXCEPT } ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable_name\u003c/code\u003e\u003c/em\u003e [, ...] ) ]\n    FROM SERVER \u003cem class=\"replaceable\"\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\n    INTO \u003cem class=\"replaceable\"\u003e\u003ccode\u003elocal_schema\u003c/code\u003e\u003c/em\u003e\n    [ OPTIONS ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e '\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e' [, ... ] ) ]","synopsis_text":"IMPORT FOREIGN SCHEMA remote_schema\n[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]\nFROM SERVER server_name\nINTO local_schema\n[ OPTIONS ( option 'value' [, ... ] ) ]"}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
