| Server IP : 104.21.25.180 / Your IP : 162.159.115.42 Web Server : Apache/2.4.37 System : Linux almalinux.duckdns.org 4.18.0-553.111.1.el8_10.x86_64 #1 SMP Sun Mar 8 20:06:07 EDT 2026 x86_64 User : ricodeal ( 1046) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/postgresql-docs/html/ |
Upload File : |
<?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>CREATE FOREIGN DATA WRAPPER</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="[email protected]" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-createextension.html" title="CREATE EXTENSION" /><link rel="next" href="sql-createforeigntable.html" title="CREATE FOREIGN TABLE" /></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">CREATE FOREIGN DATA WRAPPER</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createextension.html" title="CREATE EXTENSION">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 10.23 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-createforeigntable.html" title="CREATE FOREIGN TABLE">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-CREATEFOREIGNDATAWRAPPER"><div class="titlepage"></div><a id="id-1.9.3.62.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE FOREIGN DATA WRAPPER</span></h2><p>CREATE FOREIGN DATA WRAPPER — define a new foreign-data wrapper</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">CREATE FOREIGN DATA WRAPPER <em class="replaceable"><code>name</code></em>
[ HANDLER <em class="replaceable"><code>handler_function</code></em> | NO HANDLER ]
[ VALIDATOR <em class="replaceable"><code>validator_function</code></em> | NO VALIDATOR ]
[ OPTIONS ( <em class="replaceable"><code>option</code></em> '<em class="replaceable"><code>value</code></em>' [, ... ] ) ]</pre></div><div class="refsect1" id="id-1.9.3.62.5"><h2>Description</h2><p> <code class="command">CREATE FOREIGN DATA WRAPPER</code> creates a new
foreign-data wrapper. The user who defines a foreign-data wrapper
becomes its owner.
</p><p> The foreign-data wrapper name must be unique within the database.
</p><p> Only superusers can create foreign-data wrappers.
</p></div><div class="refsect1" id="id-1.9.3.62.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p> The name of the foreign-data wrapper to be created.
</p></dd><dt><span class="term"><code class="literal">HANDLER <em class="replaceable"><code>handler_function</code></em></code></span></dt><dd><p><em class="replaceable"><code>handler_function</code></em> 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 <code class="type">fdw_handler</code>.
</p><p> 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.
</p></dd><dt><span class="term"><code class="literal">VALIDATOR <em class="replaceable"><code>validator_function</code></em></code></span></dt><dd><p><em class="replaceable"><code>validator_function</code></em>
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 <code class="literal">NO
VALIDATOR</code> 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 <code class="type">text[]</code>, which will
contain the array of options as stored in the system catalogs,
and one of type <code class="type">oid</code>, 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
<code class="function">ereport(ERROR)</code> function.
</p></dd><dt><span class="term"><code class="literal">OPTIONS ( <em class="replaceable"><code>option</code></em> '<em class="replaceable"><code>value</code></em>' [, ... ] )</code></span></dt><dd><p> 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.
</p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.62.7"><h2>Notes</h2><p> <span class="productname">PostgreSQL</span>'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.
</p></div><div class="refsect1" id="id-1.9.3.62.8"><h2>Examples</h2><p> Create a useless foreign-data wrapper <code class="literal">dummy</code>:
</p><pre class="programlisting">CREATE FOREIGN DATA WRAPPER dummy;</pre><p>
</p><p> Create a foreign-data wrapper <code class="literal">file</code> with
handler function <code class="literal">file_fdw_handler</code>:
</p><pre class="programlisting">CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;</pre><p>
</p><p> Create a foreign-data wrapper <code class="literal">mywrapper</code> with some
options:
</p><pre class="programlisting">CREATE FOREIGN DATA WRAPPER mywrapper
OPTIONS (debug 'true');</pre></div><div class="refsect1" id="id-1.9.3.62.9"><h2>Compatibility</h2><p> <code class="command">CREATE FOREIGN DATA WRAPPER</code> conforms to ISO/IEC
9075-9 (SQL/MED), with the exception that the <code class="literal">HANDLER</code>
and <code class="literal">VALIDATOR</code> clauses are extensions and the standard
clauses <code class="literal">LIBRARY</code> and <code class="literal">LANGUAGE</code>
are not implemented in <span class="productname">PostgreSQL</span>.
</p><p> Note, however, that the SQL/MED functionality as a whole is not yet
conforming.
</p></div><div class="refsect1" id="id-1.9.3.62.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-alterforeigndatawrapper.html" title="ALTER FOREIGN DATA WRAPPER"><span class="refentrytitle">ALTER FOREIGN DATA WRAPPER</span></a>, <a class="xref" href="sql-dropforeigndatawrapper.html" title="DROP FOREIGN DATA WRAPPER"><span class="refentrytitle">DROP FOREIGN DATA WRAPPER</span></a>, <a class="xref" href="sql-createserver.html" title="CREATE SERVER"><span class="refentrytitle">CREATE SERVER</span></a>, <a class="xref" href="sql-createusermapping.html" title="CREATE USER MAPPING"><span class="refentrytitle">CREATE USER MAPPING</span></a>, <a class="xref" href="sql-createforeigntable.html" title="CREATE FOREIGN TABLE"><span class="refentrytitle">CREATE FOREIGN TABLE</span></a></span></div></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="sql-createextension.html" title="CREATE EXTENSION">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-createforeigntable.html" title="CREATE FOREIGN TABLE">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE EXTENSION </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 10.23 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE FOREIGN TABLE</td></tr></table></div></body></html>