{"Entry":{"collection":"sql","key":"create-foreign-data-wrapper","name":"CREATE FOREIGN DATA WRAPPER","aliases":["createforeigndatawrapper"],"metadata":{"aliases":["createforeigndatawrapper"],"changed_in":["9.1","19"],"changes":[{"from":"8.3","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"8.4"},{"from":"9.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters","notes","examples","compatibility"],"removed":[]},"status":"changed","synopsis":{"added":["[ HANDLER handler_function | NO HANDLER ]","[ VALIDATOR validator_function | NO VALIDATOR ]"],"removed":["[ VALIDATOR valfunction | NO VALIDATOR ]"]},"to":"9.1"},{"from":"9.2","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters","notes","see_also"],"removed":[]},"status":"changed","synopsis":null,"to":"9.3"},{"from":"18","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters"],"removed":[]},"status":"changed","synopsis":{"added":["[ CONNECTION connection_function | NO CONNECTION ]","[ OPTIONS ( option 'value' [, ... ] ) ]"],"removed":[]},"to":"19"}],"content_hash":"1dc923c29cd7474dddfc6b2d6d6bd6d5310ca95eac123f9a9a957e939c2bb8f3","derived_content_hash":"6f134668ce1a46325b21c3d80728962aef0deb50fef41151224e809a7f0e3b83","editorial":{},"first_version":"8.4","group":"foreign","imported_at":"2026-09-30T17:43:38.670648+08:00","last_version":"20","name":"CREATE FOREIGN DATA WRAPPER","object":"FOREIGN DATA WRAPPER","position":9000,"present_in":["8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"purpose":"define a new foreign-data wrapper","purpose_zh":"","related":["alter-foreign-data-wrapper","drop-foreign-data-wrapper","create-server","create-user-mapping","create-foreign-table"],"repair_provenance":{"original_source_revision":"wiki-repair-20261023:857bb4a7ba5f8b9a80cc8cd219420c4aaf0205e83a30f3b1f097852675f00871","receipt_sha256":"9dfc9bbf498af7fdd094a7f007ac1729fe5e084588c3a4cfe9fcfc6563301d74","repair":"wiki-repair-20261023"},"slug":"create-foreign-data-wrapper","source_rev":"wiki-repair-20261023:4fa04320ca0619fa5a601c3ff9685a81a15994f7990b9dd90d23a7ef37f40498","synopsis":"CREATE FOREIGN DATA WRAPPER name\n[ HANDLER handler_function | NO HANDLER ]\n[ VALIDATOR validator_function | NO VALIDATOR ]\n[ CONNECTION connection_function | NO CONNECTION ]\n[ OPTIONS ( option 'value' [, ... ] ) ]","verb":"CREATE"}},"Definition":{"Collection":"sql","Key":"create-foreign-data-wrapper","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"create-foreign-data-wrapper","SourceRevision":"wiki-repair-20261023:4fa04320ca0619fa5a601c3ff9685a81a15994f7990b9dd90d23a7ef37f40498","Facts":{"anchor":"SQL-CREATEFOREIGNDATAWRAPPER","description_zh":"定义一个新的外部数据包装器","description_zh_html":"\u003cpre\u003eCREATE FOREIGN DATA WRAPPER name\n[ HANDLER handler_function | NO HANDLER ]\n[ VALIDATOR validator_function | NO VALIDATOR ]\n[ OPTIONS ( option \u0026#x27;value\u0026#x27; [, ... ] ) ]\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eCREATE FOREIGN DATA WRAPPER\u003c/code\u003e 创建一个新的外部数据包装器。定义该外部数据包装器的用户将成为它的拥有者。\n  \u003c/p\u003e\u003cp\u003e\n   外部数据包装器名称在数据库内必须唯一。\n  \u003c/p\u003e\u003cp\u003e\n   只有超级用户能够创建外部数据包装器。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\u003c/h2\u003e\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"ZH18-AUTO-CREATE_FOREIGN_DATA_WRAPPER-VARLISTENTRY-1\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\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 id=\"ZH18-AUTO-CREATE_FOREIGN_DATA_WRAPPER-VARLISTENTRY-2\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eHANDLER \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e\n     是一个预先注册的函数的名称，该函数将被调用以取得外部表所需的执行函数。该处理器函数不能接受任何参数，并且其返回类型必须是\n     \u003ccode class=\"type\"\u003efdw_handler\u003c/code\u003e。\n     \u003c/p\u003e\u003cp\u003e\n      可以创建没有处理器函数的外部数据包装器，但使用这种包装器的外部表只能被声明，不能被访问。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-CREATE_FOREIGN_DATA_WRAPPER-VARLISTENTRY-3\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eVALIDATOR \u003cem class=\"replaceable\"\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e\n     是一个预先注册的函数的名称，该函数将被调用以检查提供给该外部数据包装器的通用选项，以及用于外部服务器、用户映射和使用该外部数据包装器的外部表的选项。如果未指定验证器函数或者指定了\n     \u003ccode class=\"literal\"\u003eNO VALIDATOR\u003c/code\u003e，则在创建时不会检查这些选项。（外部数据包装器可能会在运行时忽略无效的选项声明，或者拒绝它们，这取决于其实现。）验证器函数必须接受两个参数：一个参数的类型为\n     \u003ccode class=\"type\"\u003etext[]\u003c/code\u003e，其中包含系统目录中存储的选项数组；另一个参数的类型为 \u003ccode class=\"type\"\u003eoid\u003c/code\u003e，其值是包含这些选项的系统目录的 OID。返回类型会被忽略；该函数应当使用\n     \u003ccode class=\"function\"\u003eereport(ERROR)\u003c/code\u003e 报告无效选项。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-CREATE_FOREIGN_DATA_WRAPPER-VARLISTENTRY-4\"\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\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 的外部数据功能仍在积极开发中。查询优化能力还很初级，而且这项工作在很大程度上也留给了包装器本身。因此，未来在性能方面仍有相当大的改进空间。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e\n   创建一个无用的外部数据包装器 \u003ccode class=\"literal\"\u003edummy\u003c/code\u003e：\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nCREATE FOREIGN DATA WRAPPER dummy;\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   用处理器函数 \u003ccode class=\"literal\"\u003efile_fdw_handler\u003c/code\u003e 创建一个外部数据包装器\n   \u003ccode class=\"literal\"\u003efile\u003c/code\u003e：\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nCREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n   用一些选项创建一个外部数据包装器 \u003ccode class=\"literal\"\u003emywrapper\u003c/code\u003e：\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nCREATE FOREIGN DATA WRAPPER mywrapper\n    OPTIONS (debug 'true');\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eCREATE FOREIGN DATA WRAPPER\u003c/code\u003e 符合 ISO/IEC\n   9075-9 (SQL/MED)，但 \u003ccode class=\"literal\"\u003eHANDLER\u003c/code\u003e 和\n   \u003ccode class=\"literal\"\u003eVALIDATOR\u003c/code\u003e 子句属于扩展，而标准中的\n   \u003ccode class=\"literal\"\u003eLIBRARY\u003c/code\u003e 和 \u003ccode class=\"literal\"\u003eLANGUAGE\u003c/code\u003e 子句在 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 中尚未实现。\n  \u003c/p\u003e\u003cp\u003e\n   不过需要注意，SQL/MED 功能整体上尚未完全符合该标准。\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-alterforeigndatawrapper.html\" title=\"ALTER FOREIGN DATA WRAPPER\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER FOREIGN DATA WRAPPER\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-dropforeigndatawrapper.html\" title=\"DROP FOREIGN DATA WRAPPER\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP FOREIGN DATA WRAPPER\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, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\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\u003c/span\u003e\u003c/section\u003e","file":"sql-createforeigndatawrapper.html","lang":"en","name":"CREATE FOREIGN DATA WRAPPER","purpose":"define a new foreign-data wrapper","purpose_zh":"定义一个新的外部数据包装器","related":["alter-foreign-data-wrapper","drop-foreign-data-wrapper","create-server","create-user-mapping","create-foreign-table"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE FOREIGN DATA WRAPPER\u003c/code\u003e creates a new foreign-data wrapper. The user who defines a foreign-data wrapper becomes its owner.\u003c/p\u003e\u003cp\u003eThe foreign-data wrapper name must be unique within the database.\u003c/p\u003e\u003cp\u003eOnly superusers can create foreign-data wrappers.\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\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name of the foreign-data wrapper to be created.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eHANDLER \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e is the name of a previously registered function that will be called to retrieve the execution functions for foreign tables. The handler function must take no arguments, and its return type must be \u003ccode class=\"type\"\u003efdw_handler\u003c/code\u003e.\u003c/p\u003e\u003cp\u003eIt is possible to create a foreign-data wrapper with no handler function, but foreign tables using such a wrapper can only be declared, not accessed.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eVALIDATOR \u003cem class=\"replaceable\"\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e is the name of a previously registered function that will be called to check the generic options given to the foreign-data wrapper, as well as options for foreign servers, user mappings and foreign tables using the foreign-data wrapper. If no validator function or \u003ccode class=\"literal\"\u003eNO VALIDATOR\u003c/code\u003e is specified, then options will not be checked at creation time. (Foreign-data wrappers will possibly ignore or reject invalid option specifications at run time, depending on the implementation.) The validator function must take two arguments: one of type \u003ccode class=\"type\"\u003etext[]\u003c/code\u003e, which will contain the array of options as stored in the system catalogs, and one of type \u003ccode class=\"type\"\u003eoid\u003c/code\u003e, which will be the OID of the system catalog containing the options. The return type is ignored; the function should report invalid options using the \u003ccode class=\"function\"\u003eereport(ERROR)\u003c/code\u003e function.\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\u003eThis clause specifies options for the new foreign-data wrapper. The allowed option names and values are specific to each foreign data wrapper and are validated using the foreign-data wrapper's validator function. Option names must be unique.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003e\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e's foreign-data functionality is still under active development. Optimization of queries is primitive (and mostly left to the wrapper, too). Thus, there is considerable room for future performance improvements.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eCreate a useless foreign-data wrapper \u003ccode class=\"literal\"\u003edummy\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE FOREIGN DATA WRAPPER dummy;\n\u003c/pre\u003e\u003cp\u003eCreate a foreign-data wrapper \u003ccode class=\"literal\"\u003efile\u003c/code\u003e with handler function \u003ccode class=\"literal\"\u003efile_fdw_handler\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;\n\u003c/pre\u003e\u003cp\u003eCreate a foreign-data wrapper \u003ccode class=\"literal\"\u003emywrapper\u003c/code\u003e with some options:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE FOREIGN DATA WRAPPER mywrapper\n    OPTIONS (debug 'true');\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE FOREIGN DATA WRAPPER\u003c/code\u003e conforms to ISO/IEC 9075-9 (SQL/MED), with the exception that the \u003ccode class=\"literal\"\u003eHANDLER\u003c/code\u003e and \u003ccode class=\"literal\"\u003eVALIDATOR\u003c/code\u003e clauses are extensions and the standard clauses \u003ccode class=\"literal\"\u003eLIBRARY\u003c/code\u003e and \u003ccode class=\"literal\"\u003eLANGUAGE\u003c/code\u003e are not implemented in \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eNote, however, that the SQL/MED functionality as a whole is not yet conforming.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/alter-foreign-data-wrapper/?v=18\" title=\"ALTER FOREIGN DATA WRAPPER\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER FOREIGN DATA WRAPPER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-foreign-data-wrapper/?v=18\" title=\"DROP FOREIGN DATA WRAPPER\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP FOREIGN DATA WRAPPER\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, \u003ca href=\"/wiki/sql/create-user-mapping/?v=18\" title=\"CREATE USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\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\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"CREATE FOREIGN DATA WRAPPER \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\n    [ HANDLER \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e | NO HANDLER ]\n    [ VALIDATOR \u003cem class=\"replaceable\"\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e | NO VALIDATOR ]\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":"CREATE FOREIGN DATA WRAPPER name\n[ HANDLER handler_function | NO HANDLER ]\n[ VALIDATOR validator_function | NO VALIDATOR ]\n[ OPTIONS ( option 'value' [, ... ] ) ]","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/sql-createforeigndatawrapper.html","sha256":"d317e5f7b7380ea85ecde16b15668bbb4e15b955cbde2856d2f81c3faac002e8"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"zh_from":"same-version-pgdoc"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"create-foreign-data-wrapper","SourceDatabase":"center","Version":"18","Locale":"en","Title":"CREATE FOREIGN DATA WRAPPER","Summary":"define a new foreign-data wrapper","BodyHTML":"\u003cpre\u003eCREATE FOREIGN DATA WRAPPER name\n[ HANDLER handler_function | NO HANDLER ]\n[ VALIDATOR validator_function | NO VALIDATOR ]\n[ OPTIONS ( option \u0026#39;value\u0026#39; [, ... ] ) ]\u003c/pre\u003e\u003csection\u003e\u003ch2\u003eDescription\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eCREATE FOREIGN DATA WRAPPER\u003c/code\u003e creates a new foreign-data wrapper. The user who defines a foreign-data wrapper becomes its owner.\u003c/p\u003e\u003cp\u003eThe foreign-data wrapper name must be unique within the database.\u003c/p\u003e\u003cp\u003eOnly superusers can create foreign-data wrappers.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eParameters\u003c/h2\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name of the foreign-data wrapper to be created.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eHANDLER \u003cem\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\u003cem\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e is the name of a previously registered function that will be called to retrieve the execution functions for foreign tables. The handler function must take no arguments, and its return type must be \u003ccode\u003efdw_handler\u003c/code\u003e.\u003c/p\u003e\u003cp\u003eIt is possible to create a foreign-data wrapper with no handler function, but foreign tables using such a wrapper can only be declared, not accessed.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eVALIDATOR \u003cem\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\u003cem\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e is the name of a previously registered function that will be called to check the generic options given to the foreign-data wrapper, as well as options for foreign servers, user mappings and foreign tables using the foreign-data wrapper. If no validator function or \u003ccode\u003eNO VALIDATOR\u003c/code\u003e is specified, then options will not be checked at creation time. (Foreign-data wrappers will possibly ignore or reject invalid option specifications at run time, depending on the implementation.) The validator function must take two arguments: one of type \u003ccode\u003etext[]\u003c/code\u003e, which will contain the array of options as stored in the system catalogs, and one of type \u003ccode\u003eoid\u003c/code\u003e, which will be the OID of the system catalog containing the options. The return type is ignored; the function should report invalid options using the \u003ccode\u003eereport(ERROR)\u003c/code\u003e function.\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\u003eThis clause specifies options for the new foreign-data wrapper. The allowed option names and values are specific to each foreign data wrapper and are validated using the foreign-data wrapper\u0026#39;s validator function. Option names must be unique.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eNotes\u003c/h2\u003e\u003cp\u003e\u003cspan\u003ePostgreSQL\u003c/span\u003e\u0026#39;s foreign-data functionality is still under active development. Optimization of queries is primitive (and mostly left to the wrapper, too). Thus, there is considerable room for future performance improvements.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eExamples\u003c/h2\u003e\u003cp\u003eCreate a useless foreign-data wrapper \u003ccode\u003edummy\u003c/code\u003e:\u003c/p\u003e\u003cpre\u003eCREATE FOREIGN DATA WRAPPER dummy;\n\u003c/pre\u003e\u003cp\u003eCreate a foreign-data wrapper \u003ccode\u003efile\u003c/code\u003e with handler function \u003ccode\u003efile_fdw_handler\u003c/code\u003e:\u003c/p\u003e\u003cpre\u003eCREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;\n\u003c/pre\u003e\u003cp\u003eCreate a foreign-data wrapper \u003ccode\u003emywrapper\u003c/code\u003e with some options:\u003c/p\u003e\u003cpre\u003eCREATE FOREIGN DATA WRAPPER mywrapper\n    OPTIONS (debug \u0026#39;true\u0026#39;);\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eCompatibility\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eCREATE FOREIGN DATA WRAPPER\u003c/code\u003e conforms to ISO/IEC 9075-9 (SQL/MED), with the exception that the \u003ccode\u003eHANDLER\u003c/code\u003e and \u003ccode\u003eVALIDATOR\u003c/code\u003e clauses are extensions and the standard clauses \u003ccode\u003eLIBRARY\u003c/code\u003e and \u003ccode\u003eLANGUAGE\u003c/code\u003e are not implemented in \u003cspan\u003ePostgreSQL\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eNote, however, that the SQL/MED functionality as a whole is not yet conforming.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/alter-foreign-data-wrapper/?v=18\" title=\"ALTER FOREIGN DATA WRAPPER\" rel=\"nofollow\"\u003e\u003cspan\u003eALTER FOREIGN DATA WRAPPER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-foreign-data-wrapper/?v=18\" title=\"DROP FOREIGN DATA WRAPPER\" rel=\"nofollow\"\u003e\u003cspan\u003eDROP FOREIGN DATA WRAPPER\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, \u003ca href=\"/wiki/sql/create-user-mapping/?v=18\" title=\"CREATE USER MAPPING\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\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\u003c/span\u003e\u003c/section\u003e","SourceRevision":"wiki-repair-20261023:4fa04320ca0619fa5a601c3ff9685a81a15994f7990b9dd90d23a7ef37f40498","ContentHash":"59cb0ee6b47fdc00f6834328de3b81d7a9cb750dfc8181ba11c08e9bb117a671","Payload":{"related":["alter-foreign-data-wrapper","drop-foreign-data-wrapper","create-server","create-user-mapping","create-foreign-table"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE FOREIGN DATA WRAPPER\u003c/code\u003e creates a new foreign-data wrapper. The user who defines a foreign-data wrapper becomes its owner.\u003c/p\u003e\u003cp\u003eThe foreign-data wrapper name must be unique within the database.\u003c/p\u003e\u003cp\u003eOnly superusers can create foreign-data wrappers.\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\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name of the foreign-data wrapper to be created.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eHANDLER \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e is the name of a previously registered function that will be called to retrieve the execution functions for foreign tables. The handler function must take no arguments, and its return type must be \u003ccode class=\"type\"\u003efdw_handler\u003c/code\u003e.\u003c/p\u003e\u003cp\u003eIt is possible to create a foreign-data wrapper with no handler function, but foreign tables using such a wrapper can only be declared, not accessed.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eVALIDATOR \u003cem class=\"replaceable\"\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e is the name of a previously registered function that will be called to check the generic options given to the foreign-data wrapper, as well as options for foreign servers, user mappings and foreign tables using the foreign-data wrapper. If no validator function or \u003ccode class=\"literal\"\u003eNO VALIDATOR\u003c/code\u003e is specified, then options will not be checked at creation time. (Foreign-data wrappers will possibly ignore or reject invalid option specifications at run time, depending on the implementation.) The validator function must take two arguments: one of type \u003ccode class=\"type\"\u003etext[]\u003c/code\u003e, which will contain the array of options as stored in the system catalogs, and one of type \u003ccode class=\"type\"\u003eoid\u003c/code\u003e, which will be the OID of the system catalog containing the options. The return type is ignored; the function should report invalid options using the \u003ccode class=\"function\"\u003eereport(ERROR)\u003c/code\u003e function.\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\u003eThis clause specifies options for the new foreign-data wrapper. The allowed option names and values are specific to each foreign data wrapper and are validated using the foreign-data wrapper's validator function. Option names must be unique.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003e\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e's foreign-data functionality is still under active development. Optimization of queries is primitive (and mostly left to the wrapper, too). Thus, there is considerable room for future performance improvements.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eCreate a useless foreign-data wrapper \u003ccode class=\"literal\"\u003edummy\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE FOREIGN DATA WRAPPER dummy;\n\u003c/pre\u003e\u003cp\u003eCreate a foreign-data wrapper \u003ccode class=\"literal\"\u003efile\u003c/code\u003e with handler function \u003ccode class=\"literal\"\u003efile_fdw_handler\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;\n\u003c/pre\u003e\u003cp\u003eCreate a foreign-data wrapper \u003ccode class=\"literal\"\u003emywrapper\u003c/code\u003e with some options:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE FOREIGN DATA WRAPPER mywrapper\n    OPTIONS (debug 'true');\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE FOREIGN DATA WRAPPER\u003c/code\u003e conforms to ISO/IEC 9075-9 (SQL/MED), with the exception that the \u003ccode class=\"literal\"\u003eHANDLER\u003c/code\u003e and \u003ccode class=\"literal\"\u003eVALIDATOR\u003c/code\u003e clauses are extensions and the standard clauses \u003ccode class=\"literal\"\u003eLIBRARY\u003c/code\u003e and \u003ccode class=\"literal\"\u003eLANGUAGE\u003c/code\u003e are not implemented in \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eNote, however, that the SQL/MED functionality as a whole is not yet conforming.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/alter-foreign-data-wrapper/?v=18\" title=\"ALTER FOREIGN DATA WRAPPER\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER FOREIGN DATA WRAPPER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-foreign-data-wrapper/?v=18\" title=\"DROP FOREIGN DATA WRAPPER\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP FOREIGN DATA WRAPPER\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, \u003ca href=\"/wiki/sql/create-user-mapping/?v=18\" title=\"CREATE USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\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\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","synopsis_html":"CREATE FOREIGN DATA WRAPPER \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\n    [ HANDLER \u003cem class=\"replaceable\"\u003e\u003ccode\u003ehandler_function\u003c/code\u003e\u003c/em\u003e | NO HANDLER ]\n    [ VALIDATOR \u003cem class=\"replaceable\"\u003e\u003ccode\u003evalidator_function\u003c/code\u003e\u003c/em\u003e | NO VALIDATOR ]\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":"CREATE FOREIGN DATA WRAPPER name\n[ HANDLER handler_function | NO HANDLER ]\n[ VALIDATOR validator_function | NO VALIDATOR ]\n[ OPTIONS ( option 'value' [, ... ] ) ]"}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
