1
<!-- doc/src/sgml/ref/create_foreign_table.sgml -->
3
<refentry id="SQL-CREATEFOREIGNTABLE">
5
<refentrytitle>CREATE FOREIGN TABLE</refentrytitle>
6
<manvolnum>7</manvolnum>
7
<refmiscinfo>SQL - Language Statements</refmiscinfo>
11
<refname>CREATE FOREIGN TABLE</refname>
12
<refpurpose>define a new foreign table</refpurpose>
15
<indexterm zone="sql-createforeigntable">
16
<primary>CREATE FOREIGN TABLE</primary>
21
CREATE FOREIGN TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable> ( [
22
{ <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ NULL | NOT NULL ] }
25
SERVER <replaceable class="parameter">server_name</replaceable>
26
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
31
<refsect1 id="SQL-CREATEFOREIGNTABLE-description">
32
<title>Description</title>
35
<command>CREATE FOREIGN TABLE</command> will create a new foreign table
36
in the current database. The table will be owned by the user issuing the
41
If a schema name is given (for example, <literal>CREATE FOREIGN TABLE
42
myschema.mytable ...</>) then the table is created in the specified
43
schema. Otherwise it is created in the current schema.
44
The name of the foreign table must be
45
distinct from the name of any other foreign table, table, sequence, index,
46
or view in the same schema.
50
<command>CREATE FOREIGN TABLE</command> also automatically creates a data
51
type that represents the composite type corresponding to one row of
52
the foreign table. Therefore, foreign tables cannot have the same
53
name as any existing data type in the same schema.
58
<title>Parameters</title>
63
<term><literal>IF NOT EXISTS</></term>
66
Do not throw an error if a relation with the same name already exists.
67
A notice is issued in this case. Note that there is no guarantee that
68
the existing relation is anything like the one that would have been
75
<term><replaceable class="PARAMETER">table_name</replaceable></term>
78
The name (optionally schema-qualified) of the table to be created.
84
<term><replaceable class="PARAMETER">column_name</replaceable></term>
87
The name of a column to be created in the new table.
93
<term><replaceable class="PARAMETER">data_type</replaceable></term>
96
The data type of the column. This can include array
97
specifiers. For more information on the data types supported by
98
<productname>PostgreSQL</productname>, refer to <xref
105
<term><literal>NOT NULL</></term>
108
The column is not allowed to contain null values.
114
<term><literal>NULL</></term>
117
The column is allowed to contain null values. This is the default.
121
This clause is only provided for compatibility with
122
non-standard SQL databases. Its use is discouraged in new
129
<term><replaceable class="PARAMETER">server_name</replaceable></term>
132
The name of an existing server for the foreign table.
138
<term><literal>OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ...] )</literal></term>
141
Options to be associated with the new foreign table.
142
The allowed option names and values are specific to each foreign
143
data wrapper and are validated using the foreign-data wrapper's
144
validator function. Option names must be unique.
154
<refsect1 id="SQL-CREATEFOREIGNTABLE-examples">
155
<title>Examples</title>
158
Create foreign table <structname>films</> with <structname>film_server</>:
161
CREATE FOREIGN TABLE films (
162
code char(5) NOT NULL,
163
title varchar(40) NOT NULL,
164
did integer NOT NULL,
167
len interval hour to minute
175
<refsect1 id="SQL-CREATEFOREIGNTABLE-compatibility">
176
<title id="SQL-CREATEFOREIGNTABLE-compatibility-title">Compatibility</title>
179
The <command>CREATE FOREIGN TABLE</command> command largely conforms to the
180
<acronym>SQL</acronym> standard; however, much as with
181
<link linkend="sql-createtable"><command>CREATE TABLE</></link>,
182
<literal>NULL</> constraints and zero-column foreign tables are permitted.
188
<title>See Also</title>
190
<simplelist type="inline">
191
<member><xref linkend="sql-alterforeigntable"></member>
192
<member><xref linkend="sql-dropforeigntable"></member>
193
<member><xref linkend="sql-createtable"></member>
194
<member><xref linkend="sql-createserver"></member>