CREATE FOREIGN DATA WRAPPER
CREATE FOREIGN DATA WRAPPER — define a new foreign-data wrapper
CREATE FOREIGN DATA WRAPPER name
[ HANDLER handler_function
| NO HANDLER ]
[ VALIDATOR validator_function
| NO VALIDATOR ]
[ OPTIONS (option
'value
' [, ... ] ) ]
CREATE FOREIGN DATA WRAPPER
creates a new foreign-data wrapper. The user who defines a foreign-data wrapper becomes its owner.
The foreign-data wrapper name must be unique within the database.
Only superusers can create foreign-data wrappers.
Parameters
name
The name of the foreign-data wrapper to be created.
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
.
It is possible to create a foreign-data wrapper with no handler function, but foreign tables using such a wrapper can only be declared, not accessed.
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. 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.) 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.
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.
PostgreSQL’s foreign-data functionality is still under active development. Optimization of queries is primitive (and mostly left to the wrapper, too). Thus, there is considerable room for future performance improvements.
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');
ALTER FOREIGN DATA WRAPPER
ALTER FOREIGN DATA WRAPPER — change the definition of a foreign-data wrapper
ALTER FOREIGN DATA WRAPPER name
[ HANDLER handler_function
| NO HANDLER ]
[ VALIDATOR validator_function
| NO VALIDATOR ]
[ OPTIONS ( [ ADD | SET | DROP ]option
['value
'] [, ... ]) ]
ALTER FOREIGN DATA WRAPPERname
OWNER TO {new_owner
| CURRENT_USER | SESSION_USER }
ALTER FOREIGN DATA WRAPPERname
RENAME TOnew_name
ALTER FOREIGN DATA WRAPPER
changes the definition of a foreign-data wrapper. The first form of the command changes the support functions or the generic options of the foreign-data wrapper (at least one clause is required). The second form changes the owner of the foreign-data wrapper.
Only superusers can alter foreign-data wrappers. Additionally, only superusers can own foreign-data wrappers.
Parameters
name
The name of an existing foreign-data wrapper.
HANDLER handler_function
Specifies a new handler function for the foreign-data wrapper.
NO HANDLER
This is used to specify that the foreign-data wrapper should no longer have a handler function.
Note that foreign tables that use a foreign-data wrapper with no handler cannot be accessed.
VALIDATOR validator_function
Specifies a new validator function for the foreign-data wrapper.
Note that it is possible that pre-existing options of the foreign-data wrapper, or of dependent servers, user mappings, or foreign tables, are invalid according to the new validator. PostgreSQL does not check for this. It is up to the user to make sure that these options are correct before using the modified foreign-data wrapper. However, any options specified in this ALTER FOREIGN DATA WRAPPER
command will be checked using the new validator.
NO VALIDATOR
This is used to specify that the foreign-data wrapper should no longer have a validator function.
OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] )
Change options for the foreign-data wrapper. ADD
, SET
, and DROP
specify the action to be performed. ADD
is assumed if no operation is explicitly specified. Option names must be unique; names and values are also validated using the foreign data wrapper’s validator function, if any.
new_owner
The user name of the new owner of the foreign-data wrapper.
new_name
The new name for the foreign-data wrapper.
Examples
Change a foreign-data wrapper dbi
, add option foo
, drop bar
:
ALTER FOREIGN DATA WRAPPER dbi OPTIONS (ADD foo '1', DROP 'bar');
Change the foreign-data wrapper dbi
validator to bob.myvalidator
:
ALTER FOREIGN DATA WRAPPER dbi VALIDATOR bob.myvalidator;
DROP FOREIGN DATA WRAPPER
DROP FOREIGN DATA WRAPPER — remove a foreign-data wrapper
DROP FOREIGN DATA WRAPPER [ IF EXISTS ] name
[, ...] [ CASCADE | RESTRICT ]
DROP FOREIGN DATA WRAPPER
removes an existing foreign-data wrapper. To execute this command, the current user must be the owner of the foreign-data wrapper.
Parameters
IF EXISTS
Do not throw an error if the foreign-data wrapper does not exist. A notice is issued in this case.
name
The name of an existing foreign-data wrapper.
CASCADE
Automatically drop objects that depend on the foreign-data wrapper (such as foreign tables and servers), and in turn all objects that depend on those objects.
RESTRICT
Refuse to drop the foreign-data wrapper if any objects depend on it. This is the default.
Examples
Drop the foreign-data wrapper dbi
:
DROP FOREIGN DATA WRAPPER dbi;