<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>57.3. Foreign Data Wrapper Helper Functions</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="fdw-callbacks.html" title="57.2. Foreign Data Wrapper Callback Routines" /><link rel="next" href="fdw-planning.html" title="57.4. Foreign Data Wrapper Query Planning" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">57.3. Foreign Data Wrapper Helper Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="fdw-callbacks.html" title="57.2. Foreign Data Wrapper Callback Routines">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="fdwhandler.html" title="Chapter 57. Writing A Foreign Data Wrapper">Up</a></td><th width="60%" align="center">Chapter 57. Writing A Foreign Data Wrapper</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 11.10 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="fdw-planning.html" title="57.4. Foreign Data Wrapper Query Planning">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FDW-HELPERS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">57.3. Foreign Data Wrapper Helper Functions</h2></div></div></div><p> 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 <code class="filename">foreign/foreign.h</code> in your source file. That header also defines the struct types that are returned by these functions. </p><p> </p><pre class="programlisting"> ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid); </pre><p> This function returns a <code class="structname">ForeignDataWrapper</code> object for the foreign-data wrapper with the given OID. A <code class="structname">ForeignDataWrapper</code> object contains properties of the FDW (see <code class="filename">foreign/foreign.h</code> for details). </p><p> </p><pre class="programlisting"> ForeignServer * GetForeignServer(Oid serverid); </pre><p> This function returns a <code class="structname">ForeignServer</code> object for the foreign server with the given OID. A <code class="structname">ForeignServer</code> object contains properties of the server (see <code class="filename">foreign/foreign.h</code> for details). </p><p> </p><pre class="programlisting"> UserMapping * GetUserMapping(Oid userid, Oid serverid); </pre><p> This function returns a <code class="structname">UserMapping</code> 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 <code class="literal">PUBLIC</code>, or throw error if there is none.) A <code class="structname">UserMapping</code> object contains properties of the user mapping (see <code class="filename">foreign/foreign.h</code> for details). </p><p> </p><pre class="programlisting"> ForeignTable * GetForeignTable(Oid relid); </pre><p> This function returns a <code class="structname">ForeignTable</code> object for the foreign table with the given OID. A <code class="structname">ForeignTable</code> object contains properties of the foreign table (see <code class="filename">foreign/foreign.h</code> for details). </p><p> </p><pre class="programlisting"> List * GetForeignColumnOptions(Oid relid, AttrNumber attnum); </pre><p> 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 <code class="structname">DefElem</code>. NIL is returned if the column has no options. </p><p> Some object types have name-based lookup functions in addition to the OID-based ones: </p><p> </p><pre class="programlisting"> ForeignDataWrapper * GetForeignDataWrapperByName(const char *name, bool missing_ok); </pre><p> This function returns a <code class="structname">ForeignDataWrapper</code> 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. </p><p> </p><pre class="programlisting"> ForeignServer * GetForeignServerByName(const char *name, bool missing_ok); </pre><p> This function returns a <code class="structname">ForeignServer</code> 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. </p></div><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navfooter"><hr></hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="fdw-callbacks.html" title="57.2. Foreign Data Wrapper Callback Routines">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="fdwhandler.html" title="Chapter 57. Writing A Foreign Data Wrapper">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="fdw-planning.html" title="57.4. Foreign Data Wrapper Query Planning">Next</a></td></tr><tr><td width="40%" align="left" valign="top">57.2. Foreign Data Wrapper Callback Routines </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 11.10 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 57.4. Foreign Data Wrapper Query Planning</td></tr></table></div></body></html>