11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.120 2009/12/07 05:22:21 tgl Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.121 2010/01/28 23:21:11 petere Exp $
33PostgreSQL documentation
44-->
55
@@ -32,6 +32,16 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
3232[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
3333[ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]
3434
35+ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable>
36+ OF <replaceable class="PARAMETER">type_name</replaceable> [ (
37+ { <replaceable class="PARAMETER">column_name</replaceable> WITH OPTIONS [ DEFAULT <replaceable>default_expr</replaceable> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
38+ | <replaceable>table_constraint</replaceable> }
39+ [, ... ]
40+ ) ]
41+ [ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
42+ [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
43+ [ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]
44+
3545<phrase>where <replaceable class="PARAMETER">column_constraint</replaceable> is:</phrase>
3646
3747[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
@@ -153,6 +163,27 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
153163 </listitem>
154164 </varlistentry>
155165
166+ <varlistentry>
167+ <term><literal>OF <replaceable class="PARAMETER">type_name</replaceable></literal></term>
168+ <listitem>
169+ <para>
170+ Creates a <firstterm>typed table</firstterm>, which takes its
171+ structure from the specified composite type (name optionally
172+ schema-qualified). A typed table is tied to its type; for
173+ example the table will be dropped if the type is dropped
174+ (with <literal>DROP TYPE ... CASCADE</literal>).
175+ </para>
176+
177+ <para>
178+ When a typed table is created, then the data types of the
179+ columns are determined by the underlying composite type and are
180+ not specified by the <literal>CREATE TABLE</literal> command.
181+ But the <literal>CREATE TABLE</literal> command can add defaults
182+ and constraints to the table and can specify storage parameters.
183+ </para>
184+ </listitem>
185+ </varlistentry>
186+
156187 <varlistentry>
157188 <term><replaceable class="PARAMETER">column_name</replaceable></term>
158189 <listitem>
@@ -1182,6 +1213,17 @@ CREATE TABLE cinemas (
11821213</programlisting>
11831214 </para>
11841215
1216+ <para>
1217+ Create a composite type and a typed table:
1218+ <programlisting>
1219+ CREATE TYPE employee_type AS (name text, salary numeric);
1220+
1221+ CREATE TABLE employees OF employee_type (
1222+ PRIMARY KEY (name),
1223+ salary WITH OPTIONS DEFAULT 1000
1224+ );
1225+ </programlisting>
1226+ </para>
11851227 </refsect1>
11861228
11871229 <refsect1 id="SQL-CREATETABLE-compatibility">
@@ -1331,6 +1373,19 @@ CREATE TABLE cinemas (
13311373 and <literal>USING INDEX TABLESPACE</literal> are extensions.
13321374 </para>
13331375 </refsect2>
1376+
1377+ <refsect2>
1378+ <title>Typed Tables</title>
1379+
1380+ <para>
1381+ Typed tables implement a subset of the SQL standard. According to
1382+ the standard, a typed table has columns corresponding to the
1383+ underlying composite type as well as one other column that is
1384+ the <quote>self-referencing column</quote>. PostgreSQL does not
1385+ support these self-referencing columns explicitly, but the same
1386+ effect can be had using the OID feature.
1387+ </para>
1388+ </refsect2>
13341389 </refsect1>
13351390
13361391
@@ -1341,6 +1396,7 @@ CREATE TABLE cinemas (
13411396 <member><xref linkend="sql-altertable" endterm="sql-altertable-title"></member>
13421397 <member><xref linkend="sql-droptable" endterm="sql-droptable-title"></member>
13431398 <member><xref linkend="sql-createtablespace" endterm="sql-createtablespace-title"></member>
1399+ <member><xref linkend="sql-createtype" endterm="sql-createtype-title"></member>
13441400 </simplelist>
13451401 </refsect1>
13461402</refentry>
0 commit comments