CREATE_FOREIGN_DATA_WRAPPER(7pg17)
β¨ CREATE_FOREIGN_DATA_WRAPPER β¨
okay bestie, so this is the CREATE_FOREIGN_DATA_WRAPPER page from the PostgreSQL 17.11 manual, and we're gonna make a brand-new foreign-data wrapper together. it's giving β¨plumbingβ¨ but honestly? iconic.
πΈ NAME πΈ
CREATE_FOREIGN_DATA_WRAPPER β define a new foreign-data wrapper π
π¦ SYNOPSIS π¦
CREATE FOREIGN DATA WRAPPER name
[ HANDLER handler_function | NO HANDLER ]
[ VALIDATOR validator_function | NO VALIDATOR ]
[ OPTIONS ( option 'value' [, ... ] ) ]
copy that exactly, bestie, every bracket matters π«Ά
π DESCRIPTION π
CREATE FOREIGN DATA WRAPPER creates a new foreign-data wrapper. and the plot twist? the user who defines a foreign-data wrapper becomes its owner. main character energy, honestly π
the foreign-data wrapper name has to be unique within the database β no dupes allowed, that's the vibe check π
and listen: only superusers can create foreign-data wrappers π so if you're not one, this is not your moment. sorry not sorry.
π PARAMETERS π
nameβ the name of the foreign-data wrapper to be created. that's it, that's the name. pick a good one β¨HANDLER handler_functionβhandler_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. no cap, those are the rules.
so like... it is possible to create a foreign-data wrapper with no handler function, but heads up π: foreign tables using such a wrapper can only be declared, not accessed. so it's decorative. a little guy. not functional.
VALIDATOR validator_functionβvalidator_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. it checks everything, she's thorough π
if no validator function or NO VALIDATOR 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 β so like, your fave might just ghost your bad options later π)
the validator function must take two arguments: one of type text[], which will contain the array of options as stored in the system catalogs, and one of type oid, 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 ereport(ERROR) function. periodt β¨
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. also, option names must be unique β no doubling up, bestie π«
π§ NOTES π§
ngl, PostgreSQL's foreign-data functionality is still under active development. optimization of queries is primitive (and mostly left to the wrapper, too β she's got a lot on her plate). thus, there is considerable room for future performance improvements π± like, lots of room. so much room. it's a growth mindset situation.
fr fr: don't expect magic query planning here yet. it's a work in progress and that's okay π
β EXAMPLES β
create a useless foreign-data wrapper dummy (she does nothing and we love her for it):
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. so like... mostly conforming, but don't @ me π
π SEE ALSO π
ALTER FOREIGN DATA WRAPPER(ALTER_FOREIGN_DATA_WRAPPER(7))DROP FOREIGN DATA WRAPPER(DROP_FOREIGN_DATA_WRAPPER(7))CREATE SERVER(CREATE_SERVER(7))CREATE USER MAPPING(CREATE_USER_MAPPING(7))CREATE FOREIGN TABLE(CREATE_FOREIGN_TABLE(7))
and that's the whole page, bestie π«Ά go forth and wrap some foreign data. this was PostgreSQL 17.11, dated 2026 β mwah, love u, bye πππ¦
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms