[ WITH OIDS | WITHOUT OIDS ]
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
-CREATE FOREIGN TABLE <replaceable class="PARAMETER">table_name</replaceable>
- OF <replaceable class="PARAMETER">type_name</replaceable> [ (
- { <replaceable class="PARAMETER">column_name</replaceable> WITH OPTIONS [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
- | <replaceable>table_constraint</replaceable> }
- [, ... ]
-) ]
-[ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
- SERVER <replaceable class="parameter">server_name</replaceable>
-[ WITH OIDS | WITHOUT OIDS ]
-[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
-
<phrase>where <replaceable class="PARAMETER">column_constraint</replaceable> is:</phrase>
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
</listitem>
</varlistentry>
- <varlistentry>
- <term><literal>OF <replaceable class="PARAMETER">type_name</replaceable></literal></term>
- <listitem>
- <para>
- Creates a <firstterm>typed table</firstterm>, which takes its
- structure from the specified composite type (name optionally
- schema-qualified). A typed table is tied to its type; for
- example the table will be dropped if the type is dropped
- (with <literal>DROP TYPE ... CASCADE</literal>).
- </para>
-
- <para>
- When a typed table is created, then the data types of the
- columns are determined by the underlying composite type and are
- not specified by the <literal>CREATE FOREIGN TABLE</literal> command.
- But the <literal>CREATE FOREIGN TABLE</literal> command can add defaults
- and constraints to the table.
- </para>
- </listitem>
- </varlistentry>
-
<varlistentry>
<term><replaceable class="PARAMETER">column_name</replaceable></term>
<listitem>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><literal>OPTIONS ( <replaceable class="PARAMETER">option</replaceable> = '<replaceable class="PARAMETER">value</replaceable>' [, ...] )</literal></term>
+ <listitem>
+ <para>
+ This clause specified options for the new foreign table.
+ The allowed option names and values are specific to each foreign
+ data wrapper and are validated using the foreign-data wrapper
+ library. Option names must be unique.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><literal>INHERITS ( <replaceable>parent_table</replaceable> [, ... ] )</literal></term>
<listitem>
</programlisting>
</para>
- <para>
- Create a composite type and a typed foreign table:
-<programlisting>
-CREATE TYPE employee_type AS (name text, salary numeric);
-
-CREATE FOREIGN TABLE employees OF employee_type (
- salary WITH OPTIONS CHECK (salary > 0)
-)
-SERVER employee_server;
-</programlisting>
- </para>
</refsect1>
<refsect1 id="SQL-CREATEFOREIGNTABLE-compatibility">
</para>
</refsect2>
- <refsect2>
- <title>Typed Tables</title>
-
- <para>
- Typed tables implement a subset of the SQL standard. According to
- the standard, a typed table has columns corresponding to the
- underlying composite type as well as one other column that is
- the <quote>self-referencing column</quote>. PostgreSQL does not
- support these self-referencing columns explicitly, but the same
- effect can be had using the OID feature.
- </para>
- </refsect2>
</refsect1>
OptTableElementList TableElementList OptInherit definition
OptTypedTableElementList TypedTableElementList
OptForeignTableElementList ForeignTableElementList
- OptTypedForeignTableElementList TypedForeignTableElementList
reloptions opt_reloptions
OptWith opt_distinct opt_definition func_args func_args_list
func_args_with_defaults func_args_with_defaults_list
%type <vsetstmt> set_rest SetResetClause
%type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
- ForeignTableElement TypedForeignTableElement
- ForeignConstraintElem
+ ForeignTableElement ForeignConstraintElem
%type <node> CheckConstraintElem UniqueConstraintElem PrimaryKeyConstraintElem
ExcludeConstraintElem ForeignKeyConstraintElem
%type <node> columnDef columnOptions
n->options = $10;
$$ = (Node *) n;
}
- | CREATE FOREIGN TABLE qualified_name OF any_name
- OptTypedForeignTableElementList
- SERVER name OptWith create_generic_options
- {
- CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
- $4->istemp = false;
- n->base.relation = $4;
- n->base.tableElts = $7;
- n->base.ofTypename = makeTypeNameFromNameList($6);
- n->base.ofTypename->location = @6;
- n->base.options = $10;
- /* FDW-specific data */
- n->servername = $9;
- n->options = $11;
- $$ = (Node *) n;
- }
;
OptForeignTableElementList:
}
;
-OptTypedForeignTableElementList:
- '(' TypedForeignTableElementList ')' { $$ = $2; }
- | /*EMPTY*/ { $$ = NIL; }
- ;
-
ForeignTableElementList:
ForeignTableElement
{
}
;
-TypedForeignTableElementList:
- TypedForeignTableElement
- {
- $$ = list_make1($1);
- }
- | TypedForeignTableElementList ',' TypedForeignTableElement
- {
- $$ = lappend($1, $3);
- }
- ;
-
ForeignTableElement:
foreignColumnDef { $$ = $1; }
| ForeignTableLikeClause { $$ = $1; }
| ForeignTableConstraint { $$ = $1; }
;
-TypedForeignTableElement:
- columnOptions { $$ = $1; }
- | ForeignTableConstraint { $$ = $1; }
- ;
-
/* TODO: support GENERIC OPTIONS of foreign column */
foreignColumnDef: ColId Typename ForeignColQualList
{