CREATE_FOREIGN_DATA_WRAPPER(7pg17)

πŸ“¦ version 17.11, in opensuse-leap 16.0

✨ 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_function is 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 be fdw_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_function is 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 πŸ‘‘


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