| 1 |
<!-- |
| 2 |
doc/src/sgml/ref/create_foreign_data_wrapper.sgml |
| 3 |
PostgreSQL documentation |
| 4 |
--> |
| 5 |
|
| 6 |
<refentry id="sql-createforeigndatawrapper"> |
| 7 |
<indexterm zone="sql-createforeigndatawrapper"> |
| 8 |
<primary>CREATE FOREIGN DATA WRAPPER</primary> |
| 9 |
</indexterm> |
| 10 |
|
| 11 |
<refmeta> |
| 12 |
<refentrytitle>CREATE FOREIGN DATA WRAPPER</refentrytitle> |
| 13 |
<manvolnum>7</manvolnum> |
| 14 |
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
| 15 |
</refmeta> |
| 16 |
|
| 17 |
<refnamediv> |
| 18 |
<refname>CREATE FOREIGN DATA WRAPPER</refname> |
| 19 |
<refpurpose>define a new foreign-data wrapper</refpurpose> |
| 20 |
</refnamediv> |
| 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> |
| 84 |
is the 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, user mappings and foreign tables |
| 87 |
using the 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 |
<productname>PostgreSQL</productname>'s foreign-data functionality is still under |
| 121 |
active development. Optimization of queries is primitive (and mostly left |
| 122 |
to the wrapper, too). Thus, there is considerable room for future |
| 123 |
performance improvements. |
| 124 |
</para> |
| 125 |
</refsect1> |
| 126 |
|
| 127 |
<refsect1> |
| 128 |
<title>Examples</title> |
| 129 |
|
| 130 |
<para> |
| 131 |
Create a useless foreign-data wrapper <literal>dummy</literal>: |
| 132 |
<programlisting> |
| 133 |
CREATE FOREIGN DATA WRAPPER dummy; |
| 134 |
</programlisting> |
| 135 |
</para> |
| 136 |
|
| 137 |
<para> |
| 138 |
Create a foreign-data wrapper <literal>file</literal> with |
| 139 |
handler function <literal>file_fdw_handler</literal>: |
| 140 |
<programlisting> |
| 141 |
CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler; |
| 142 |
</programlisting> |
| 143 |
</para> |
| 144 |
|
| 145 |
<para> |
| 146 |
Create a foreign-data wrapper <literal>mywrapper</literal> with some |
| 147 |
options: |
| 148 |
<programlisting> |
| 149 |
CREATE FOREIGN DATA WRAPPER mywrapper |
| 150 |
OPTIONS (debug 'true'); |
| 151 |
</programlisting></para> |
| 152 |
</refsect1> |
| 153 |
|
| 154 |
<refsect1> |
| 155 |
<title>Compatibility</title> |
| 156 |
|
| 157 |
<para> |
| 158 |
<command>CREATE FOREIGN DATA WRAPPER</command> conforms to ISO/IEC |
| 159 |
9075-9 (SQL/MED), with the exception that the <literal>HANDLER</literal> |
| 160 |
and <literal>VALIDATOR</literal> clauses are extensions and the standard |
| 161 |
clauses <literal>LIBRARY</literal> and <literal>LANGUAGE</literal> |
| 162 |
are not implemented in <productname>PostgreSQL</productname>. |
| 163 |
</para> |
| 164 |
|
| 165 |
<para> |
| 166 |
Note, however, that the SQL/MED functionality as a whole is not yet |
| 167 |
conforming. |
| 168 |
</para> |
| 169 |
</refsect1> |
| 170 |
|
| 171 |
<refsect1> |
| 172 |
<title>See Also</title> |
| 173 |
|
| 174 |
<simplelist type="inline"> |
| 175 |
<member><xref linkend="sql-alterforeigndatawrapper"/></member> |
| 176 |
<member><xref linkend="sql-dropforeigndatawrapper"/></member> |
| 177 |
<member><xref linkend="sql-createserver"/></member> |
| 178 |
<member><xref linkend="sql-createusermapping"/></member> |
| 179 |
<member><xref linkend="sql-createforeigntable"/></member> |
| 180 |
</simplelist> |
| 181 |
</refsect1> |
| 182 |
|
| 183 |
</refentry> |