Postgresql 中文操作指南

59.1. Foreign Data Wrapper Functions #

FDW 作者需要实现一个处理程序函数,还可以选择一个验证器函数。这两个函数都必须使用版本 1 界面以编译语言(如 C)编写。有关 C 语言调用约定和动态加载的详细信息,请参阅 Section 38.10

The FDW author needs to implement a handler function, and optionally a validator function. Both functions must be written in a compiled language such as C, using the version-1 interface. For details on C language calling conventions and dynamic loading, see Section 38.10.

处理程序函数只需返回一个函数指针结构,指向由规划器、执行器和各种维护命令调用的回调函数。编写 FDW 的大部分工作在于实现这些回调函数。处理程序函数必须向 PostgreSQL 注册为不带参数且返回特殊伪类型 fdw_handler。回调函数是普通的 C 函数,在 SQL 层不可见或不可调用。回调函数在 Section 59.2 中进行描述。

The handler function simply returns a struct of function pointers to callback functions that will be called by the planner, executor, and various maintenance commands. Most of the effort in writing an FDW is in implementing these callback functions. The handler function must be registered with PostgreSQL as taking no arguments and returning the special pseudo-type fdw_handler. The callback functions are plain C functions and are not visible or callable at the SQL level. The callback functions are described in Section 59.2.

验证程序函数负责验证 CREATEALTER 命令中给出的选项,以及使用包装器的外部服务器、用户映射和外部表。验证程序函数必须注册为接受两个参数,分别是一个包含要验证的选项的文本数组,以及一个表示选项所关联的对象类型的 OID。后者对应于将对象存储在其中的系统目录的 OID,其中之一:

The validator function is responsible for validating options given in CREATE and ALTER commands for its foreign data wrapper, as well as foreign servers, user mappings, and foreign tables using the wrapper. The validator function must be registered as taking two arguments, a text array containing the options to be validated, and an OID representing the type of object the options are associated with. The latter corresponds to the OID of the system catalog the object would be stored in, one of:

如果没有提供验证程序函数,则在对象创建时或对象更改时不对选项进行检查。

If no validator function is supplied, options are not checked at object creation time or object alteration time.