CREATE_FOREIGN_DATA_WRAPPER(7pg16)
β¨ CREATE FOREIGN DATA WRAPPER β¨
okay bestie, welcome to the CREATE FOREIGN DATA WRAPPER page β straight outta the PostgreSQL 16.15 Documentation π
this one's all about making a brand-new foreign-data wrapper, and yes it's as iconic as it sounds π«Ά
πΈ NAME πΈ
CREATE_FOREIGN_DATA_WRAPPER β define a new foreign-data wrapper. literally that's the whole job, and it ate π
π SYNOPSIS π
CREATE FOREIGN DATA WRAPPER name
[ HANDLER handler_function | NO HANDLER ]
[ VALIDATOR validator_function | NO VALIDATOR ]
[ OPTIONS ( option 'value' [, ... ] ) ]
look at that syntax glow-up β¨ every bracket is optional, so you can go minimal or maximalist, your call queen π
π¦ DESCRIPTION π¦
So CREATE FOREIGN DATA WRAPPER creates a new foreign-data wrapper. and ngl, the way that the user who defines a foreign-data wrapper becomes its owner? main character energy fr fr π
The foreign-data wrapper name must be unique within the database β no duplicate names, that's the vibe check and you will be carded π¨
Also important: only superusers can create foreign-data wrappers. sorry bestie, it's a whole exclusive club π
π PARAMETERS π
nameβ the name of the foreign-data wrapper you're creating. pick something cute but, again, it has to be unique in the database πHANDLER handler_functionβhandler_functionis the name of a previously registered function that gets 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, that's a hard requirement π₯
and plot twist: it is possible to create a foreign-data wrapper with no handler function at all β but foreign tables using such a wrapper can only be declared, not accessed. so like, it exists but it can't do anything π decorative wrapper, basically π
VALIDATOR validator_functionβvalidator_functionis the name of a previously registered function that gets called to check the generic options given to the foreign-data wrapper, plus options for foreign servers, user mappings and foreign tables using that foreign-data wrapper. if no validator function is specified, or you sayNO VALIDATOR, then options will not be checked at creation time. (and heads up: foreign-data wrappers will possibly ignore or reject invalid option specifications at run time, depending on the implementation β iykyk, it's giving "we'll see" π)
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 π¨
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 β no repeats, periodt π
β NOTES β
real talk: PostgreSQL's foreign-data functionality is still under active development. optimization of queries is primitive (and mostly left to the wrapper, too π). so there's considerable room for future performance improvements β it's giving "watch this space" π¦
π EXAMPLES π
create a useless foreign-data wrapper dummy β yes, "useless" is the official vibe, we love a humble icon:
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');
three examples, all slaying in their own way π
π 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... partial slay.
π«Ά 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))
go read those next bestie, they're all linked in the group chat π¬
and that's the whole page!! mwah π this came to you from PostgreSQL 16.15, dated 2026 β same energy as the original footer, just cuter π byeee, go create some wrappers π§ββοΈβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-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