CREATE FOREIGN DATA WRAPPER
Define a new external data wrapper.
Summary
CREATE FOREIGN DATA WRAPPER name
[ HANDLER handler_function | NO HANDLER ]
[ VALIDATOR validator_function | NO VALIDATOR ]
[ OPTIONS ( [ mpp_execute { 'master' | 'any' | 'all segments' } [, ] ] option 'value' [, ... ] ) ]
describe
CREATE FOREIGN DATA WRAPPER creates a new external data wrapper in the current database. The user who defines an external data wrapper will become its owner.
Only superusers can create external data wrappers.
Parameters
name
- The name of the external data wrapper to be created. This name must be unique in the database.
HANDLER handler_function
- YMatrix database call to retrieve the name of the previously registered function of the executing function of the external table. The hander_function must take no parameters, and its return type must be fdw_handler.
External data wrappers without handler functions can be created, but only such wrapper declarations can be used without accessing external tables.
VALIDATOR validator_function
- YMatrix database call to check the name of the previously registered function that is provided to the option provided to the external data wrapper. This function also checks options for external servers, user maps, and external tables using external data wrappers. If the validator function is not specified or NO VALIDATOR is specified, the YMatrix database does not check options when created. (Depending on the implementation, an external data wrapper may ignore or reject invalid options at runtime.)
Validator_function must take two parameters: one is the text[] type, which contains the option array stored in the system catalog, and the other is the oid type, which identifies the OID of the system catalog containing the options.
The return type will be ignored; the validator_function should use the eerport(ERROR) function to report invalid options.
OPTIONS ( option 'value' [, ... ] )
- Options for new external data wrappers. The option name must be unique. The option name and value are specific to the external data wrapper and are verified using the validator_function of the external data wrapper.
mpp_execute { 'master' | 'any' | 'all segments' }
- An option to identify the host from which the external data wrapper requests data:
- master (default) - Request data from the master host.
- any — Request data from the master host or any segment, depending on which path is less expensive.
- all segments — Request data from all segments. To support this option value, the external data wrapper must have a policy that matches the segment with the data.
- The mpp_execute option can be specified in multiple commands: CREATE FOREIGN TABLE, CREATE SERVER and CREATE FOREIGN DATA WRAPPER. External table settings take precedence over external server settings, followed by external data wrapper settings.
Note
The external data wrapper functionality is still under development. The optimization of the query is original (mostly left to the wrapper).
Example
Create a useless external data wrapper named dummy:
CREATE FOREIGN DATA WRAPPER dummy;
Create an external data wrapper named file using a handler called file_fdw_handler:
CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;
Create an external data wrapper called mywrapper, which includes an option:
CREATE FOREIGN DATA WRAPPER mywrapper OPTIONS (debug 'true');
compatibility
CREATE FOREIGN DATA WRAPPER complies with ISO/IEC 9075-9 (SQL/MED), but the LIBRARY and VALIDATOR clauses are extensions and exceptions, while the standard clauses LIBRARY and LANGUAGE are not implemented in the YMatrix database.
But please note that the entire SQL/MED function has not met the requirements yet.
See also
ALTER FOREIGN DATA WRAPPER , DROP FOREIGN DATA WRAPPER