CREATE FOREIGN DATA WRAPPER
define a new foreign-data wrapper
English manual coverage begins with PostgreSQL 6.4. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- anchor
- SQL-CREATEFOREIGNDATAWRAPPER
- file
- sql-createforeigndatawrapper.html
- lang
- en
- name
- CREATE FOREIGN DATA WRAPPER
- purpose
- define a new foreign-data wrapper
- purpose zh
- 定义一个新的外部数据包装器
- sections same as
- Unknown
- slug
- 18
- synopsis text
- CREATE FOREIGN DATA WRAPPER name [ HANDLER handler_function | NO HANDLER ] [ VALIDATOR validator_function | NO VALIDATOR ] [ OPTIONS ( option 'value' [, ... ] ) ]
Syntax
CREATE FOREIGN DATA WRAPPER name
[ HANDLER handler_function | NO HANDLER ]
[ VALIDATOR validator_function | NO VALIDATOR ]
[ OPTIONS ( option 'value' [, ... ] ) ]Syntax diagrams
Read left to right. Branches are choices, bypasses are optional, loops repeat. Select an underlined parameter to open its rule.
Definition PG 18
CREATE FOREIGN DATA WRAPPER name [ HANDLER handler_function | NO HANDLER ] [ VALIDATOR validator_function | NO VALIDATOR ] [ OPTIONS ( option 'value' [, ... ] ) ]
Description
CREATE FOREIGN DATA WRAPPER creates a new foreign-data wrapper. The user who defines a foreign-data wrapper becomes its owner.
The foreign-data wrapper name must be unique within the database.
Only superusers can create foreign-data wrappers.
Parameters
nameThe name of the foreign-data wrapper to be created.
HANDLERhandler_functionhandler_functionis 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 befdw_handler.It 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.
VALIDATORvalidator_functionvalidator_functionis 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 orNO VALIDATORis 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 typetext[], which will contain the array of options as stored in the system catalogs, and one of typeoid, which will be the OID of the system catalog containing the options. The return type is ignored; the function should report invalid options using theereport(ERROR)function.OPTIONS (option'value' [, ... ] )This 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.
Notes
PostgreSQL'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.
Examples
Create a useless foreign-data wrapper dummy:
CREATE FOREIGN DATA WRAPPER dummy;
Create a foreign-data wrapper file with handler function file_fdw_handler:
CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;
Create a foreign-data wrapper mywrapper with some options:
CREATE FOREIGN DATA WRAPPER mywrapper
OPTIONS (debug 'true');
Compatibility
CREATE FOREIGN DATA WRAPPER conforms to ISO/IEC 9075-9 (SQL/MED), with the exception that the HANDLER and VALIDATOR clauses are extensions and the standard clauses LIBRARY and LANGUAGE are not implemented in PostgreSQL.
Note, however, that the SQL/MED functionality as a whole is not yet conforming.
See Also
ALTER FOREIGN DATA WRAPPER, DROP FOREIGN DATA WRAPPER, CREATE SERVER, CREATE USER MAPPING, CREATE FOREIGN TABLECompare versions
Complete source facts
synopsis html
CREATE FOREIGN DATA WRAPPER <em class="replaceable"><code>name</code></em>
[ HANDLER <em class="replaceable"><code>handler_function</code></em> | NO HANDLER ]
[ VALIDATOR <em class="replaceable"><code>validator_function</code></em> | NO VALIDATOR ]
[ OPTIONS ( <em class="replaceable"><code>option</code></em> '<em class="replaceable"><code>value</code></em>' [, ... ] ) ]Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · wiki-repair-20261023:4fa04320ca0619fa5a601c3ff9685a81a15994f7990b9dd90d23a7ef37f40498
Text language: en · wiki-repair-20261023:4fa04320ca0619fa5a601c3ff9685a81a15994f7990b9dd90d23a7ef37f40498