Updated on 2024-05-07 GMT+08:00

CREATE FOREIGN DATA WRAPPER

Description

Creates a foreign data wrapper. The user who created the foreign data wrapper becomes its owner.

Precautions

  • The name of the foreign data wrapper must be unique in the database.
  • Only initial users and system administrators can create foreign data wrappers.

Syntax

CREATE FOREIGN DATA WRAPPER name
[ HANDLER handler_function | NO HANDLER ]
[ VALIDATOR validator_function | NO VALIDATOR ]
[ OPTIONS ( option 'value' [, ... ] ) ];

Parameters

  • name

    Specifies the name of the foreign data wrapper to be created.

  • HADNLER handler_function

    handler_function is the name of a registered function used to retrieve execution functions for foreign tables. The handler function must have no arguments, and its return type must be fdw_handler.

    It is possible to create foreign data wrappers without processor functions, but foreign tables that use such wrappers can only be declared and cannot be accessed.

  • VALIDATOR validator_function

    validator_function is the name of a registered function used to check the common options provided to the foreign data wrapper, as well as the options for the foreign server, user mapping, and foreign table that use the foreign data wrapper. If there is no validator function or NO VALIDATOR is declared, the option is not checked during creation. (The foreign data wrapper may ignore or reject invalid option descriptions at runtime, depending on the implementation.) The validator function must accept two arguments: one is of text[] type, which will contain an array of options stored in the system directory, and the other is of OID type, which will be the OID of the system directory that contains the options. The return type is ignored. The function should report invalid options using the ereport(ERROR) function.

  • OPTIONS ( option 'value' [, ... ] )

    This clause declares options for the new foreign data wrapper. The allowed option names and values are specific to each foreign data wrapper and are validated by the validator function of the foreign data wrapper. The option name must be unique.

Example

-- Create a useless foreign-data wrapper dummy.
gaussdb=# CREATE FOREIGN DATA WRAPPER dummy;

-- Create a foreign data wrapper file with the handler function file_fdw_handler.
gaussdb=# CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;

-- Create a foreign data wrapper mywrapper with some options.
gaussdb=# CREATE FOREIGN DATA WRAPPER mywrapper OPTIONS (debug 'true');