Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b46727e

Browse files
committed
doc: Reorganize CREATE TABLE / LIKE option documentation
This section once started out small but has now grown quite a bit and needs a bit of structure. Rewrite as list, add documentation of EXCLUDING, and improve the documentation of INCLUDING ALL instead of just listing all the options again. per report from Yugo Nagata that EXCLUDING was not documented, that part reviewed by Daniel Gustafsson, most of the rewrite was by me
1 parent fc057b2 commit b46727e

File tree

1 file changed

+113
-55
lines changed

1 file changed

+113
-55
lines changed

doc/src/sgml/ref/create_table.sgml

+113-55
Original file line numberDiff line numberDiff line change
@@ -570,66 +570,124 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
570570
possible to include data of the new table in scans of the original
571571
table.
572572
</para>
573-
<para>
574-
Default expressions for the copied column definitions will be copied
575-
only if <literal>INCLUDING DEFAULTS</literal> is specified. The
576-
default behavior is to exclude default expressions, resulting in the
577-
copied columns in the new table having null defaults.
578-
Note that copying defaults that call database-modification functions,
579-
such as <function>nextval</function>, may create a functional linkage between
580-
the original and new tables.
581-
</para>
582-
<para>
583-
Any identity specifications of copied column definitions will only be
584-
copied if <literal>INCLUDING IDENTITY</literal> is specified. A new
585-
sequence is created for each identity column of the new table, separate
586-
from the sequences associated with the old table.
587-
</para>
588-
<para>
589-
Not-null constraints are always copied to the new table.
590-
<literal>CHECK</literal> constraints will be copied only if
591-
<literal>INCLUDING CONSTRAINTS</literal> is specified.
592-
No distinction is made between column constraints and table
593-
constraints.
594-
</para>
595-
<para>
596-
Extended statistics are copied to the new table if
597-
<literal>INCLUDING STATISTICS</literal> is specified.
598-
</para>
599-
<para>
600-
Indexes, <literal>PRIMARY KEY</literal>, <literal>UNIQUE</literal>,
601-
and <literal>EXCLUDE</literal> constraints on the original table will be
602-
created on the new table only if <literal>INCLUDING INDEXES</literal>
603-
is specified. Names for the new indexes and constraints are
604-
chosen according to the default rules, regardless of how the originals
605-
were named. (This behavior avoids possible duplicate-name failures for
606-
the new indexes.)
607-
</para>
608-
<para>
609-
<literal>STORAGE</literal> settings for the copied column definitions will be
610-
copied only if <literal>INCLUDING STORAGE</literal> is specified. The
611-
default behavior is to exclude <literal>STORAGE</literal> settings, resulting
612-
in the copied columns in the new table having type-specific default
613-
settings. For more on <literal>STORAGE</literal> settings, see
614-
<xref linkend="storage-toast"/>.
615-
</para>
616-
<para>
617-
Comments for the copied columns, constraints, and indexes
618-
will be copied only if <literal>INCLUDING COMMENTS</literal>
619-
is specified. The default behavior is to exclude comments, resulting in
620-
the copied columns and constraints in the new table having no comments.
621-
</para>
622-
<para>
623-
<literal>INCLUDING ALL</literal> is an abbreviated form of
624-
<literal>INCLUDING COMMENTS INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING IDENTITY INCLUDING INDEXES INCLUDING STATISTICS INCLUDING STORAGE</literal>.
625-
</para>
626-
<para>
627-
Note that unlike <literal>INHERITS</literal>, columns and
573+
<para>
574+
Also unlike <literal>INHERITS</literal>, columns and
628575
constraints copied by <literal>LIKE</literal> are not merged with similarly
629576
named columns and constraints.
630577
If the same name is specified explicitly or in another
631578
<literal>LIKE</literal> clause, an error is signaled.
632579
</para>
580+
<para>
581+
The optional <replaceable>like_option</replaceable> clauses specify
582+
which additional properties of the original table to copy. Specifying
583+
<literal>INCLUDING</literal> copies the property, specifying
584+
<literal>EXCLUDING</literal> omits the property.
585+
<literal>EXCLUDING</literal> is the default. If multiple specifications
586+
are made for the same kind of object, the last one is used. The
587+
available options are:
588+
589+
<variablelist>
590+
<varlistentry>
591+
<term><literal>INCLUDING COMMENTS</literal></term>
592+
<listitem>
593+
<para>
594+
Comments for the copied columns, constraints, and indexes will be
595+
copied. The default behavior is to exclude comments, resulting in
596+
the copied columns and constraints in the new table having no
597+
comments.
598+
</para>
599+
</listitem>
600+
</varlistentry>
601+
602+
<varlistentry>
603+
<term><literal>INCLUDING CONSTRAINTS</literal></term>
604+
<listitem>
605+
<para>
606+
<literal>CHECK</literal> constraints will be copied. No distinction
607+
is made between column constraints and table constraints. Not-null
608+
constraints are always copied to the new table.
609+
</para>
610+
</listitem>
611+
</varlistentry>
612+
613+
<varlistentry>
614+
<term><literal>INCLUDING DEFAULTS</literal></term>
615+
<listitem>
616+
<para>
617+
Default expressions for the copied column definitions will be
618+
copied. Otherwise, default expressions are not copied, resulting in
619+
the copied columns in the new table having null defaults. Note that
620+
copying defaults that call database-modification functions, such as
621+
<function>nextval</function>, may create a functional linkage
622+
between the original and new tables.
623+
</para>
624+
</listitem>
625+
</varlistentry>
626+
627+
<varlistentry>
628+
<term><literal>INCLUDING IDENTITY</literal></term>
629+
<listitem>
630+
<para>
631+
Any identity specifications of copied column definitions will be
632+
copied. A new sequence is created for each identity column of the
633+
new table, separate from the sequences associated with the old
634+
table.
635+
</para>
636+
</listitem>
637+
</varlistentry>
638+
639+
<varlistentry>
640+
<term><literal>INCLUDING INDEXES</literal></term>
641+
<listitem>
642+
<para>
643+
Indexes, <literal>PRIMARY KEY</literal>, <literal>UNIQUE</literal>,
644+
and <literal>EXCLUDE</literal> constraints on the original table
645+
will be created on the new table. Names for the new indexes and
646+
constraints are chosen according to the default rules, regardless of
647+
how the originals were named. (This behavior avoids possible
648+
duplicate-name failures for the new indexes.)
649+
</para>
650+
</listitem>
651+
</varlistentry>
652+
653+
<varlistentry>
654+
<term><literal>INCLUDING STATISTICS</literal></term>
655+
<listitem>
656+
<para>
657+
Extended statistics are copied to the new table.
658+
</para>
659+
</listitem>
660+
</varlistentry>
661+
662+
<varlistentry>
663+
<term><literal>INCLUDING STORAGE</literal></term>
664+
<listitem>
665+
<para>
666+
<literal>STORAGE</literal> settings for the copied column
667+
definitions will be copied. The default behavior is to exclude
668+
<literal>STORAGE</literal> settings, resulting in the copied columns
669+
in the new table having type-specific default settings. For more on
670+
<literal>STORAGE</literal> settings, see <xref
671+
linkend="storage-toast"/>.
672+
</para>
673+
</listitem>
674+
</varlistentry>
675+
676+
<varlistentry>
677+
<term><literal>INCLUDING ALL</literal></term>
678+
<listitem>
679+
<para>
680+
<literal>INCLUDING ALL</literal> is an abbreviated form selecting
681+
all the available individual options. (It could be useful to write
682+
individual <literal>EXCLUDING</literal> clauses after
683+
<literal>INCLUDING ALL</literal> to select all but some specific
684+
options.)
685+
</para>
686+
</listitem>
687+
</varlistentry>
688+
</variablelist>
689+
</para>
690+
633691
<para>
634692
The <literal>LIKE</literal> clause can also be used to copy column
635693
definitions from views, foreign tables, or composite types.

0 commit comments

Comments
 (0)