3
PostgreSQL documentation
6
<refentry id="SQL-CREATEFOREIGNDATAWRAPPER">
8
<refentrytitle id="sql-createforeigndatawrapper-title">CREATE FOREIGN DATA WRAPPER</refentrytitle>
9
<refmiscinfo>SQL - Language Statements</refmiscinfo>
13
<refname>CREATE FOREIGN DATA WRAPPER</refname>
14
<refpurpose>define a new foreign-data wrapper</refpurpose>
17
<indexterm zone="sql-createforeigndatawrapper">
18
<primary>CREATE FOREIGN DATA WRAPPER</primary>
23
CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
24
[ VALIDATOR <replaceable class="parameter">valfunction</replaceable> | NO VALIDATOR ]
25
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
30
<title>Description</title>
33
<command>CREATE FOREIGN DATA WRAPPER</command> creates a new
34
foreign-data wrapper. The user who defines a foreign-data wrapper
39
The foreign-data wrapper name must be unique within the database.
43
Only superusers can create foreign-data wrappers.
48
<title>Parameters</title>
52
<term><replaceable class="parameter">name</replaceable></term>
55
The name of the foreign-data wrapper to be created.
61
<term><literal>VALIDATOR <replaceable class="parameter">valfunction</replaceable></literal></term>
64
<replaceable class="parameter">valfunction</replaceable> is the
65
name of a previously registered function that will be called to
66
check the generic options given to the foreign-data wrapper, as
67
well as to foreign servers and user mappings using the
68
foreign-data wrapper. If no validator function or <literal>NO
69
VALIDATOR</literal> is specified, then options will not be
70
checked at creation time. (Foreign-data wrappers will possibly
71
ignore or reject invalid option specifications at run time,
72
depending on the implementation.) The validator function must
73
take two arguments: one of type <type>text[]</type>, which will
74
contain the array of options as stored in the system catalogs,
75
and one of type <type>oid</type>, which will be the OID of the
76
system catalog containing the options, or zero if the context is
77
not known. The return type is ignored; the function should
78
indicate invalid options using
79
the <function>ereport()</function> function.
85
<term><literal>OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] )</literal></term>
88
This clause specifies options for the new foreign-data wrapper.
89
The allowed option names and values are specific to each foreign
90
data wrapper and are validated using the foreign-data wrapper
91
library. Option names must be unique.
102
At the moment, the foreign-data wrapper functionality is very
103
rudimentary. The purpose of foreign-data wrappers, foreign
104
servers, and user mappings is to store this information in a
105
standard way so that it can be queried by interested applications.
106
The functionality to actually query external data does not exist
111
There is currently one foreign-data wrapper validator function
113
<filename>postgresql_fdw_validator</filename>, which accepts
114
options corresponding to <application>libpq</> connection
120
<title>Examples</title>
123
Create a foreign-data wrapper <literal>dummy</>:
125
CREATE FOREIGN DATA WRAPPER dummy;
130
Create a foreign-data wrapper <literal>postgresql</> with
131
validator function <literal>postgresql_fdw_validator</>:
133
CREATE FOREIGN DATA WRAPPER postgresql VALIDATOR postgresql_fdw_validator;
138
Create a foreign-data wrapper <literal>mywrapper</> with some
141
CREATE FOREIGN DATA WRAPPER mywrapper
142
OPTIONS (debug 'true');
148
<title>Compatibility</title>
151
<command>CREATE FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
152
9075-9 (SQL/MED), with the exception that
153
the <literal>VALIDATOR</literal> clause is an extension and the
154
clauses <literal>LIBRARY</literal> and <literal>LANGUAGE</literal>
155
are not yet implemented in PostgreSQL.
159
Note, however, that the SQL/MED functionality as a whole is not yet
165
<title>See Also</title>
167
<simplelist type="inline">
168
<member><xref linkend="sql-alterforeigndatawrapper" endterm="sql-alterforeigndatawrapper-title"></member>
169
<member><xref linkend="sql-dropforeigndatawrapper" endterm="sql-dropforeigndatawrapper-title"></member>
170
<member><xref linkend="sql-createserver" endterm="sql-createserver-title"></member>
171
<member><xref linkend="sql-createusermapping" endterm="sql-createusermapping-title"></member>