1
1
<!--
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 $
3
3
PostgreSQL documentation
4
4
-->
5
5
@@ -32,6 +32,16 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
32
32
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
33
33
[ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]
34
34
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
+
35
45
<phrase>where <replaceable class="PARAMETER">column_constraint</replaceable> is:</phrase>
36
46
37
47
[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
@@ -153,6 +163,27 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
153
163
</listitem>
154
164
</varlistentry>
155
165
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
+
156
187
<varlistentry>
157
188
<term><replaceable class="PARAMETER">column_name</replaceable></term>
158
189
<listitem>
@@ -1182,6 +1213,17 @@ CREATE TABLE cinemas (
1182
1213
</programlisting>
1183
1214
</para>
1184
1215
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>
1185
1227
</refsect1>
1186
1228
1187
1229
<refsect1 id="SQL-CREATETABLE-compatibility">
@@ -1331,6 +1373,19 @@ CREATE TABLE cinemas (
1331
1373
and <literal>USING INDEX TABLESPACE</literal> are extensions.
1332
1374
</para>
1333
1375
</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>
1334
1389
</refsect1>
1335
1390
1336
1391
@@ -1341,6 +1396,7 @@ CREATE TABLE cinemas (
1341
1396
<member><xref linkend="sql-altertable" endterm="sql-altertable-title"></member>
1342
1397
<member><xref linkend="sql-droptable" endterm="sql-droptable-title"></member>
1343
1398
<member><xref linkend="sql-createtablespace" endterm="sql-createtablespace-title"></member>
1399
+ <member><xref linkend="sql-createtype" endterm="sql-createtype-title"></member>
1344
1400
</simplelist>
1345
1401
</refsect1>
1346
1402
</refentry>
0 commit comments