CREATE_FOREIGN_DATA_WRAPPER(7pg13)
π CREATE_FOREIGN_DATA_WRAPPER β define a new foreign-data wrapper β¨
okay bestie so this is the PostgreSQL 13.23 docs page for CREATE_FOREIGN_DATA_WRAPPER (manual page CREATE_F...A WRAPPER(7), the truncated title is giving classic manpage energy, we love her anyway π). She's a SQL command, she's iconic, she makes foreign-data wrappers out of thin air. Let's get into it π¦
β¨ SYNOPSIS β¨
CREATE FOREIGN DATA WRAPPER name
[ HANDLER handler_function | NO HANDLER ]
[ VALIDATOR validator_function | NO VALIDATOR ]
[ OPTIONS ( option 'value' [, ... ] ) ]
that's the whole shape of it, no cap π«Ά
πΈ DESCRIPTION πΈ
so CREATE FOREIGN DATA WRAPPER creates a new foreign-data wrapper. and literally the moment you define one, you become its owner. main character energy, you earned it π
the foreign-data wrapper name has to be unique within the database β no duplicates, periodt.
and here's the bummer: only superusers can create foreign-data wrappers. if that's not you, this command is not your moment π
π PARAMETERS π
nameβ the name of the foreign-data wrapper you're creating. pick something cute, it's yours now πHANDLER handler_functionβhandler_functionis the name of a function you already registered, and it gets called to retrieve the execution functions for foreign tables. it must take no arguments, and its return type must befdw_handler. π§
and yes, you can create a foreign-data wrapper with no handler function at all β but foreign tables using that wrapper can only be declared, not accessed. so likeβ¦ decorative. a vibe, not a function π
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 that use the foreign-data wrapper. if you specify no validator function (orNO VALIDATOR), 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, you know, at your own risk π)
the validator function must take two arguments: one of type text[], which holds the array of options as stored in the system catalogs, and one of type oid, which is the OID of the system catalog containing those 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 get validated using the foreign-data wrapper's validator function. option names must be unique β no repeats, we don't do that here π
π NOTES π
ngl, PostgreSQL's foreign-data functionality is still under active development. optimization of queries is primitive (and mostly left to the wrapper, too π). so like, there is considerable room for future performance improvements. it's giving "we're working on it" and honestly? relatable π«Ά
π₯ EXAMPLES π₯
create a useless foreign-data wrapper dummy (she does nothing and she's still beloved):
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');
slay, three little examples, all ate β¨
π 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. yes bestie, the whole thing. we said what we said π
π 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))
okay that's the whole page, go forth and wrap ur data fr fr πΈπβ¨
PostgreSQL 13.23 Β· 2025 Β· CREATE F...A WRAPPER(7) β mwah, that's the tea, see u in the next manpage bestie π«Άππ¦
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-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