]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/create_foreign_data_wrapper.sgml
Add support for piping COPY to/from an external program.
[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  </refsect1>
125
126  <refsect1>
127   <title>Examples</title>
128
129   <para>
130    Create a useless foreign-data wrapper <literal>dummy</>:
131 <programlisting>
132 CREATE FOREIGN DATA WRAPPER dummy;
133 </programlisting>
134   </para>
135
136   <para>
137    Create a foreign-data wrapper <literal>file</> with
138    handler function <literal>file_fdw_handler</>:
139 <programlisting>
140 CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;
141 </programlisting>
142   </para>
143
144   <para>
145    Create a foreign-data wrapper <literal>mywrapper</> with some
146    options:
147 <programlisting>
148 CREATE FOREIGN DATA WRAPPER mywrapper
149     OPTIONS (debug 'true');
150 </programlisting></para>
151  </refsect1>
152
153  <refsect1>
154   <title>Compatibility</title>
155
156   <para>
157    <command>CREATE FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
158    9075-9 (SQL/MED), with the exception that the <literal>HANDLER</literal>
159    and <literal>VALIDATOR</literal> clauses are extensions and the standard
160    clauses <literal>LIBRARY</literal> and <literal>LANGUAGE</literal>
161    are not implemented in PostgreSQL.
162   </para>
163
164   <para>
165    Note, however, that the SQL/MED functionality as a whole is not yet
166    conforming.
167   </para>
168  </refsect1>
169
170  <refsect1>
171   <title>See Also</title>
172
173   <simplelist type="inline">
174    <member><xref linkend="sql-alterforeigndatawrapper"></member>
175    <member><xref linkend="sql-dropforeigndatawrapper"></member>
176    <member><xref linkend="sql-createserver"></member>
177    <member><xref linkend="sql-createusermapping"></member>
178   </simplelist>
179  </refsect1>
180
181 </refentry>