Postgresql 中文操作指南
59.3. Foreign Data Wrapper Helper Functions #
核心服务器导出了几个帮助器函数,以便外来数据包装器的开发者可以轻松获得外来数据包装器相关对象的属性,例如,外来数据包装器选项。要使用这些函数中的任何一个,需要在你的源文件中包含头文件 foreign/foreign.h。该头文件还定义了这些函数返回的结构类型。
Several helper functions are exported from the core server so that authors of foreign data wrappers can get easy access to attributes of FDW-related objects, such as FDW options. To use any of these functions, you need to include the header file foreign/foreign.h in your source file. That header also defines the struct types that are returned by these functions.
ForeignDataWrapper *
GetForeignDataWrapperExtended(Oid fdwid, bits16 flags);
该函数返回带有给定 OID 的外来数据包装器的 ForeignDataWrapper 对象。ForeignDataWrapper 对象包含外来数据包装器的属性(有关详细信息,请参阅 foreign/foreign.h)。flags 是按位或运算的位掩码,表示一组额外的选项。它可以取值 FDW_MISSING_OK,在这种情况下,NULL 结果会返回给调用者,而不是对未定义对象返回错误。
This function returns a ForeignDataWrapper object for the foreign-data wrapper with the given OID. A ForeignDataWrapper object contains properties of the FDW (see foreign/foreign.h for details). flags is a bitwise-or’d bit mask indicating an extra set of options. It can take the value FDW_MISSING_OK, in which case a NULL result is returned to the caller instead of an error for an undefined object.
ForeignDataWrapper *
GetForeignDataWrapper(Oid fdwid);
该函数返回带有给定 OID 的外来数据包装器的 ForeignDataWrapper 对象。ForeignDataWrapper 对象包含外来数据包装器的属性(有关详细信息,请参阅 foreign/foreign.h)。
This function returns a ForeignDataWrapper object for the foreign-data wrapper with the given OID. A ForeignDataWrapper object contains properties of the FDW (see foreign/foreign.h for details).
ForeignServer *
GetForeignServerExtended(Oid serverid, bits16 flags);
该函数返回带有给定 OID 的外来服务器的 ForeignServer 对象。ForeignServer 对象包含服务器的属性(有关详细信息,请参阅 foreign/foreign.h)。flags 是按位或运算的位掩码,表示一组额外的选项。它可以取值 FSV_MISSING_OK,在这种情况下,NULL 结果会返回给调用者,而不是对未定义对象返回错误。
This function returns a ForeignServer object for the foreign server with the given OID. A ForeignServer object contains properties of the server (see foreign/foreign.h for details). flags is a bitwise-or’d bit mask indicating an extra set of options. It can take the value FSV_MISSING_OK, in which case a NULL result is returned to the caller instead of an error for an undefined object.
ForeignServer *
GetForeignServer(Oid serverid);
该函数返回带有给定 OID 的外来服务器的 ForeignServer 对象。ForeignServer 对象包含服务器的属性(有关详细信息,请参阅 foreign/foreign.h)。
This function returns a ForeignServer object for the foreign server with the given OID. A ForeignServer object contains properties of the server (see foreign/foreign.h for details).
UserMapping *
GetUserMapping(Oid userid, Oid serverid);
该函数返回给定服务器上给定角色的 UserMapping 对象用户映射。(如果没有针对特定用户的映射,它将返回 PUBLIC 的映射,如果不存在,则引发错误。)UserMapping 对象包含用户映射的属性(有关详细信息,请参阅 foreign/foreign.h)。
This function returns a UserMapping object for the user mapping of the given role on the given server. (If there is no mapping for the specific user, it will return the mapping for PUBLIC, or throw error if there is none.) A UserMapping object contains properties of the user mapping (see foreign/foreign.h for details).
ForeignTable *
GetForeignTable(Oid relid);
该函数返回带有给定 OID 的外来表的 ForeignTable 对象。ForeignTable 对象包含外来表的属性(有关详细信息,请参阅 foreign/foreign.h)。
This function returns a ForeignTable object for the foreign table with the given OID. A ForeignTable object contains properties of the foreign table (see foreign/foreign.h for details).
List *
GetForeignColumnOptions(Oid relid, AttrNumber attnum);
该函数返回具有给定外来表 OID 和属性编号的列的列外来数据包装器选项,形式为 DefElem 列表。如果列没有选项,则返回 NIL。
This function returns the per-column FDW options for the column with the given foreign table OID and attribute number, in the form of a list of DefElem. NIL is returned if the column has no options.
除了基于 OID 以外的一些对象类型还具有基于名称的查找函数:
Some object types have name-based lookup functions in addition to the OID-based ones:
ForeignDataWrapper *
GetForeignDataWrapperByName(const char *name, bool missing_ok);
该函数返回带有给定名称的外来数据包装器的 ForeignDataWrapper 对象。如果未找到包装器,如果 missing_ok 为 true,则返回 NULL,否则引发错误。
This function returns a ForeignDataWrapper object for the foreign-data wrapper with the given name. If the wrapper is not found, return NULL if missing_ok is true, otherwise raise an error.
ForeignServer *
GetForeignServerByName(const char *name, bool missing_ok);
该函数返回带有给定名称的外来服务器的 ForeignServer 对象。如果未找到服务器,如果 missing_ok 为 true,则返回 NULL,否则引发错误。
This function returns a ForeignServer object for the foreign server with the given name. If the server is not found, return NULL if missing_ok is true, otherwise raise an error.