In the SQL/MED portion of the SQL standard and in PostgreSQL, the WRAPPER keyword appears within CREATE FOREIGN DATA WRAPPER. A foreign data wrapper (FDW) is a plug-in module that implements the routines required to read, write, and manage data stored outside the database—such as another relational system, a CSV file, or an API. Once a wrapper is installed, you can create foreign servers and foreign tables that map to the external resource, then run ordinary SELECT, INSERT, UPDATE, or DELETE statements against them. The wrapper abstracts connection handling, data type mapping, and pushdown capabilities. Caveats: each FDW supports its own option set; write support may be partial; performance depends on the external source; SECURITY DEFINER functions used as handlers must be trusted.
wrapper_name
(identifier) - Name of the foreign data wrapper.handler_function
(regproc) - Function that returns fdw_handler and contains callback routines.validator_function
(regproc) - Function that validates OPTIONS clauses.OPTIONS
(key/value list) - Wrapper specific configuration such as connection strings or timeouts.CREATE FOREIGN SERVER, FOREIGN TABLE, IMPORT FOREIGN SCHEMA, EXTENSION, dblink
SQL:2008 (SQL/MED) and PostgreSQL 9.1
A wrapper is the plug-in that implements the FDW API, while a foreign server is a configuration object that points to a specific external source using that wrapper.
Most wrappers are shipped as extensions. Run CREATE EXTENSION wrapper_name; then the wrapper, handler, and validator objects become available.
Yes. Store passwords in a .pgpass file or use PostgreSQL secrets managers, then omit the password option in USER MAPPING to avoid exposing secrets in DDL.
Queries against foreign tables will error or hang until they reach the statement timeout. Consider setting connection retries or timeouts in the wrapper options.