diff options
| author | Peter Eisentraut <peter_e@gmx.net> | 2010-01-28 23:21:13 +0000 | 
|---|---|---|
| committer | Peter Eisentraut <peter_e@gmx.net> | 2010-01-28 23:21:13 +0000 | 
| commit | e7b3349a8ad7afaad565c573fbd65fb46af6abbe (patch) | |
| tree | f1140afea215e53e2f4430adbb0c666ffdec4752 /doc/src/sgml | |
| parent | 1f98cccb941823d241120ca86df264d7ebbcaec5 (diff) | |
Type table feature
This adds the CREATE TABLE name OF type command, per SQL standard.
Diffstat (limited to 'doc/src/sgml')
| -rw-r--r-- | doc/src/sgml/information_schema.sgml | 20 | ||||
| -rw-r--r-- | doc/src/sgml/ref/create_table.sgml | 58 | 
2 files changed, 72 insertions, 6 deletions
| diff --git a/doc/src/sgml/information_schema.sgml b/doc/src/sgml/information_schema.sgml index 4888b647d3c..124bbc3ac29 100644 --- a/doc/src/sgml/information_schema.sgml +++ b/doc/src/sgml/information_schema.sgml @@ -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> diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index e315843187c..7044e86685d 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -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> ] @@ -154,6 +164,27 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR     </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>       <para> @@ -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> | 
