mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Type table feature
This adds the CREATE TABLE name OF type command, per SQL standard.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.44 2009/12/31 14:41:23 petere Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.45 2010/01/28 23:21:10 petere Exp $ -->
|
||||
|
||||
<chapter id="information-schema">
|
||||
<title>The Information Schema</title>
|
||||
@ -4750,19 +4750,29 @@ ORDER BY c.ordinal_position;
|
||||
<row>
|
||||
<entry><literal>user_defined_type_catalog</literal></entry>
|
||||
<entry><type>sql_identifier</type></entry>
|
||||
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
|
||||
<entry>
|
||||
If the table is a typed table, the name of the database that
|
||||
contains the underlying data type (always the current
|
||||
database), else null.
|
||||
</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><literal>user_defined_type_schema</literal></entry>
|
||||
<entry><type>sql_identifier</type></entry>
|
||||
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
|
||||
<entry>
|
||||
If the table is a typed table, the name of the schema that
|
||||
contains the underlying data type, else null.
|
||||
</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><literal>user_defined_type_name</literal></entry>
|
||||
<entry><type>sql_identifier</type></entry>
|
||||
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
|
||||
<entry>
|
||||
If the table is a typed table, the name of the underlying data
|
||||
type, else null.
|
||||
</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
@ -4778,7 +4788,7 @@ ORDER BY c.ordinal_position;
|
||||
<row>
|
||||
<entry><literal>is_typed</literal></entry>
|
||||
<entry><type>yes_or_no</type></entry>
|
||||
<entry>Applies to a feature not available in <productname>PostgreSQL</></entry>
|
||||
<entry><literal>YES</literal> if the table is a typed table, <literal>NO</literal> if not</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.120 2009/12/07 05:22:21 tgl Exp $
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.121 2010/01/28 23:21:11 petere Exp $
|
||||
PostgreSQL documentation
|
||||
-->
|
||||
|
||||
@ -32,6 +32,16 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
|
||||
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
|
||||
[ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]
|
||||
|
||||
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable>
|
||||
OF <replaceable class="PARAMETER">type_name</replaceable> [ (
|
||||
{ <replaceable class="PARAMETER">column_name</replaceable> WITH OPTIONS [ DEFAULT <replaceable>default_expr</replaceable> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
|
||||
| <replaceable>table_constraint</replaceable> }
|
||||
[, ... ]
|
||||
) ]
|
||||
[ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
|
||||
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
|
||||
[ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]
|
||||
|
||||
<phrase>where <replaceable class="PARAMETER">column_constraint</replaceable> is:</phrase>
|
||||
|
||||
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
|
||||
@ -153,6 +163,27 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
|
||||
</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 TABLE</literal> command.
|
||||
But the <literal>CREATE TABLE</literal> command can add defaults
|
||||
and constraints to the table and can specify storage parameters.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="PARAMETER">column_name</replaceable></term>
|
||||
<listitem>
|
||||
@ -1182,6 +1213,17 @@ CREATE TABLE cinemas (
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Create a composite type and a typed table:
|
||||
<programlisting>
|
||||
CREATE TYPE employee_type AS (name text, salary numeric);
|
||||
|
||||
CREATE TABLE employees OF employee_type (
|
||||
PRIMARY KEY (name),
|
||||
salary WITH OPTIONS DEFAULT 1000
|
||||
);
|
||||
</programlisting>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 id="SQL-CREATETABLE-compatibility">
|
||||
@ -1331,6 +1373,19 @@ CREATE TABLE cinemas (
|
||||
and <literal>USING INDEX TABLESPACE</literal> are extensions.
|
||||
</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>
|
||||
|
||||
|
||||
@ -1341,6 +1396,7 @@ CREATE TABLE cinemas (
|
||||
<member><xref linkend="sql-altertable" endterm="sql-altertable-title"></member>
|
||||
<member><xref linkend="sql-droptable" endterm="sql-droptable-title"></member>
|
||||
<member><xref linkend="sql-createtablespace" endterm="sql-createtablespace-title"></member>
|
||||
<member><xref linkend="sql-createtype" endterm="sql-createtype-title"></member>
|
||||
</simplelist>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
Reference in New Issue
Block a user