CREATE_FOREIGN_DATA_WRAPPER(7)

โœจ CREATE FOREIGN DATA WRAPPER(7) โœจ

okay bestie, buckle up, we're doing the CREATE_FOREIGN_DATA_WRAPPER page ๐Ÿ’…


๐ŸŒธ 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' [, ... ] ) ]

๐Ÿ’– DESCRIPTION ๐Ÿ’–

CREATE FOREIGN DATA WRAPPER creates a new foreign-data wrapper. And the way that the user who defines a foreign-data wrapper becomes its owner?? automatic. it's giving main character energy fr fr ๐Ÿ‘‘

the foreign-data wrapper name has to be unique within the database, no duplicates allowed, no copycats, periodt.

and heads up: only superusers can create foreign-data wrappers. like, that's the vibe check you gotta pass first ๐Ÿ”ฅ


๐Ÿฆ‹ PARAMETERS ๐Ÿฆ‹

  • name โ€” the name of the foreign-data wrapper to be created. simple. iconic. that's it.
  • HANDLER handler_function โ€” handler_function is 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 be fdw_handler.

and yes, you can create a foreign-data wrapper with no handler function, but โ€” and this is the important part โ€” foreign tables using such a wrapper can only be declared, not accessed. so like, decorative only. all dressed up with nowhere to go ๐Ÿ˜ญ

  • VALIDATOR validator_function โ€” validator_function is 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 don't specify a validator function, or you say NO VALIDATOR, then options will not be checked at creation time. (and ngl, 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 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. slay ๐Ÿซถ
  • 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, that's the rule โœจ

๐Ÿ‘‘ NOTES ๐Ÿ‘‘

okay so 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 growing, bestie, give it time ๐ŸŒฑ


๐ŸŒˆ 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. so like, mostly compliant but not fully, iykyk ๐Ÿ™ˆ


๐Ÿ“ SEE ALSO ๐Ÿ“


and that's the whole page bestie, you ate that ๐Ÿ’…โœจ

this lil masterpiece is brought to you by PostgreSQL 18.6, dated 2026, filed under CREATE FOREIGN DATA WRAPPER(7) โ€” go forth and wrap some foreign data, mwah ๐ŸŽ€๐Ÿ’–