Postgresql 中文操作指南
CREATE FOREIGN DATA WRAPPER
CREATE FOREIGN DATA WRAPPER — 定义新的外国数据包装器
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' [, ... ] ) ]
Description
CREATE FOREIGN DATA WRAPPER 创建新的外国数据包装器。定义外国数据包装器的用户将成为其所有者。
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.
-
Notes
PostgreSQL 的外来数据功能仍在积极开发中。对查询的优化还是原始的(而且大多也留给包装程序)。因此,未来还有相当大的性能提升的空间。
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
创建无用的外来数据包装程序 dummy :
Create a useless foreign-data wrapper dummy:
CREATE FOREIGN DATA WRAPPER dummy;
使用处理程序函数 file_fdw_handler 创建外来数据包装程序 file :
Create a foreign-data wrapper file with handler function file_fdw_handler:
CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;
使用一些选项创建外来数据包装程序 mywrapper :
Create a foreign-data wrapper mywrapper with some options:
CREATE FOREIGN DATA WRAPPER mywrapper
OPTIONS (debug 'true');
Compatibility
CREATE FOREIGN DATA WRAPPER 符合 ISO/IEC 9075-9(SQL/MED), HANDLER 和 VALIDATOR 子句是扩展名且标准子句 LIBRARY 和 LANGUAGE 未在 PostgreSQL 中实施这一例外情况除外。
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.
但是,请注意,SQL/MED 功能作为一个整体尚未符合。
Note, however, that the SQL/MED functionality as a whole is not yet conforming.