2 doc/src/sgml/ref/create_foreign_data_wrapper.sgml
3 PostgreSQL documentation
6 <refentry id="SQL-CREATEFOREIGNDATAWRAPPER">
8 <refentrytitle>CREATE FOREIGN DATA WRAPPER</refentrytitle>
9 <manvolnum>7</manvolnum>
10 <refmiscinfo>SQL - Language Statements</refmiscinfo>
14 <refname>CREATE FOREIGN DATA WRAPPER</refname>
15 <refpurpose>define a new foreign-data wrapper</refpurpose>
18 <indexterm zone="sql-createforeigndatawrapper">
19 <primary>CREATE FOREIGN DATA WRAPPER</primary>
24 CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
25 [ HANDLER <replaceable class="parameter">handler_function</replaceable> | NO HANDLER ]
26 [ VALIDATOR <replaceable class="parameter">validator_function</replaceable> | NO VALIDATOR ]
27 [ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
32 <title>Description</title>
35 <command>CREATE FOREIGN DATA WRAPPER</command> creates a new
36 foreign-data wrapper. The user who defines a foreign-data wrapper
41 The foreign-data wrapper name must be unique within the database.
45 Only superusers can create foreign-data wrappers.
50 <title>Parameters</title>
54 <term><replaceable class="parameter">name</replaceable></term>
57 The name of the foreign-data wrapper to be created.
63 <term><literal>HANDLER <replaceable class="parameter">handler_function</replaceable></literal></term>
65 <para><replaceable class="parameter">handler_function</replaceable> is the
66 name of a previously registered function that will be called to
67 retrieve the execution functions for foreign tables.
68 The handler function must take no arguments, and
69 its return type must be <type>fdw_handler</type>.
73 It is possible to create a foreign-data wrapper with no handler
74 function, but foreign tables using such a wrapper can only be declared,
81 <term><literal>VALIDATOR <replaceable class="parameter">validator_function</replaceable></literal></term>
83 <para><replaceable class="parameter">validator_function</replaceable> is the
84 name of a previously registered function that will be called to
85 check the generic options given to the foreign-data wrapper, as
86 well as options for foreign servers and user mappings using the
87 foreign-data wrapper. If no validator function or <literal>NO
88 VALIDATOR</literal> is specified, then options will not be
89 checked at creation time. (Foreign-data wrappers will possibly
90 ignore or reject invalid option specifications at run time,
91 depending on the implementation.) The validator function must
92 take two arguments: one of type <type>text[]</type>, which will
93 contain the array of options as stored in the system catalogs,
94 and one of type <type>oid</type>, which will be the OID of the
95 system catalog containing the options. The return type is ignored;
96 the function should report invalid options using the
97 <function>ereport(ERROR)</function> function.
103 <term><literal>OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] )</literal></term>
106 This clause specifies options for the new foreign-data wrapper.
107 The allowed option names and values are specific to each foreign
108 data wrapper and are validated using the foreign-data wrapper's
109 validator function. Option names must be unique.
120 At the moment, the foreign-data wrapper functionality is rudimentary.
121 There is no support for updating a foreign table, and optimization of
122 queries is primitive (and mostly left to the wrapper, too).
126 There is one built-in foreign-data wrapper validator function
128 <filename>postgresql_fdw_validator</filename>, which accepts
129 options corresponding to <application>libpq</> connection
135 <title>Examples</title>
138 Create a useless foreign-data wrapper <literal>dummy</>:
140 CREATE FOREIGN DATA WRAPPER dummy;
145 Create a foreign-data wrapper <literal>file</> with
146 handler function <literal>file_fdw_handler</>:
148 CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;
153 Create a foreign-data wrapper <literal>mywrapper</> with some
156 CREATE FOREIGN DATA WRAPPER mywrapper
157 OPTIONS (debug 'true');
158 </programlisting></para>
162 <title>Compatibility</title>
165 <command>CREATE FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
166 9075-9 (SQL/MED), with the exception that the <literal>HANDLER</literal>
167 and <literal>VALIDATOR</literal> clauses are extensions and the standard
168 clauses <literal>LIBRARY</literal> and <literal>LANGUAGE</literal>
169 are not implemented in PostgreSQL.
173 Note, however, that the SQL/MED functionality as a whole is not yet
179 <title>See Also</title>
181 <simplelist type="inline">
182 <member><xref linkend="sql-alterforeigndatawrapper"></member>
183 <member><xref linkend="sql-dropforeigndatawrapper"></member>
184 <member><xref linkend="sql-createserver"></member>
185 <member><xref linkend="sql-createusermapping"></member>