]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/create_foreign_data_wrapper.sgml
Create a "sort support" interface API for faster sorting.
[postgresql] / doc / src / sgml / ref / create_foreign_data_wrapper.sgml
1 <!--
2 doc/src/sgml/ref/create_foreign_data_wrapper.sgml
3 PostgreSQL documentation
4 -->
5
6 <refentry id="SQL-CREATEFOREIGNDATAWRAPPER">
7  <refmeta>
8   <refentrytitle>CREATE FOREIGN DATA WRAPPER</refentrytitle>
9   <manvolnum>7</manvolnum>
10   <refmiscinfo>SQL - Language Statements</refmiscinfo>
11  </refmeta>
12
13  <refnamediv>
14   <refname>CREATE FOREIGN DATA WRAPPER</refname>
15   <refpurpose>define a new foreign-data wrapper</refpurpose>
16  </refnamediv>
17
18  <indexterm zone="sql-createforeigndatawrapper">
19   <primary>CREATE FOREIGN DATA WRAPPER</primary>
20  </indexterm>
21
22  <refsynopsisdiv>
23 <synopsis>
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>' [, ... ] ) ]
28 </synopsis>
29  </refsynopsisdiv>
30
31  <refsect1>
32   <title>Description</title>
33
34   <para>
35    <command>CREATE FOREIGN DATA WRAPPER</command> creates a new
36    foreign-data wrapper.  The user who defines a foreign-data wrapper
37    becomes its owner.
38   </para>
39
40   <para>
41    The foreign-data wrapper name must be unique within the database.
42   </para>
43
44   <para>
45    Only superusers can create foreign-data wrappers.
46   </para>
47  </refsect1>
48
49  <refsect1>
50   <title>Parameters</title>
51
52   <variablelist>
53    <varlistentry>
54     <term><replaceable class="parameter">name</replaceable></term>
55     <listitem>
56      <para>
57       The name of the foreign-data wrapper to be created.
58      </para>
59     </listitem>
60    </varlistentry>
61
62    <varlistentry>
63     <term><literal>HANDLER <replaceable class="parameter">handler_function</replaceable></literal></term>
64     <listitem>
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>.
70      </para>
71
72      <para>
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,
75       not accessed.
76      </para>
77     </listitem>
78    </varlistentry>
79
80    <varlistentry>
81     <term><literal>VALIDATOR <replaceable class="parameter">validator_function</replaceable></literal></term>
82     <listitem>
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.
98      </para>
99     </listitem>
100    </varlistentry>
101
102    <varlistentry>
103     <term><literal>OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] )</literal></term>
104     <listitem>
105      <para>
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.
110      </para>
111     </listitem>
112    </varlistentry>
113   </variablelist>
114  </refsect1>
115
116  <refsect1>
117   <title>Notes</title>
118
119   <para>
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).
123   </para>
124
125   <para>
126    There is one built-in foreign-data wrapper validator function
127    provided:
128    <filename>postgresql_fdw_validator</filename>, which accepts
129    options corresponding to <application>libpq</> connection
130    parameters.
131   </para>
132  </refsect1>
133
134  <refsect1>
135   <title>Examples</title>
136
137   <para>
138    Create a useless foreign-data wrapper <literal>dummy</>:
139 <programlisting>
140 CREATE FOREIGN DATA WRAPPER dummy;
141 </programlisting>
142   </para>
143
144   <para>
145    Create a foreign-data wrapper <literal>file</> with
146    handler function <literal>file_fdw_handler</>:
147 <programlisting>
148 CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;
149 </programlisting>
150   </para>
151
152   <para>
153    Create a foreign-data wrapper <literal>mywrapper</> with some
154    options:
155 <programlisting>
156 CREATE FOREIGN DATA WRAPPER mywrapper
157     OPTIONS (debug 'true');
158 </programlisting></para>
159  </refsect1>
160
161  <refsect1>
162   <title>Compatibility</title>
163
164   <para>
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.
170   </para>
171
172   <para>
173    Note, however, that the SQL/MED functionality as a whole is not yet
174    conforming.
175   </para>
176  </refsect1>
177
178  <refsect1>
179   <title>See Also</title>
180
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>
186   </simplelist>
187  </refsect1>
188
189 </refentry>