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

Commit c6f8d17

Browse files
committed
Doc: clarify that CREATE TABLE discards redundant unique constraints.
The SQL standard says that redundant unique constraints are disallowed, but we long ago decided that throwing an error would be too user-unfriendly, so we just drop redundant ones. The docs weren't very clear about that though, as this behavior was only explained for PRIMARY KEY vs UNIQUE, not UNIQUE vs UNIQUE. While here, I couldn't resist doing some copy-editing and markup-fixing on the adjacent text about INCLUDE options. Per bug #16767 from Matthias vd Meent. Discussion: https://postgr.es/m/16767-1714a2056ca516d0@postgresql.org
1 parent c5ba660 commit c6f8d17

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

doc/src/sgml/ref/create_table.sgml

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -877,15 +877,17 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
877877
<varlistentry>
878878
<term><literal>UNIQUE</literal> (column constraint)</term>
879879
<term><literal>UNIQUE ( <replaceable class="parameter">column_name</replaceable> [, ... ] )</literal>
880-
<optional> INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...]) </optional> (table constraint)</term>
880+
<optional> <literal>INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...])</literal> </optional> (table constraint)</term>
881881

882882
<listitem>
883883
<para>
884884
The <literal>UNIQUE</literal> constraint specifies that a
885885
group of one or more columns of a table can contain
886-
only unique values. The behavior of the unique table constraint
887-
is the same as that for column constraints, with the additional
888-
capability to span multiple columns.
886+
only unique values. The behavior of a unique table constraint
887+
is the same as that of a unique column constraint, with the
888+
additional capability to span multiple columns. The constraint
889+
therefore enforces that any two rows must differ in at least one
890+
of these columns.
889891
</para>
890892

891893
<para>
@@ -894,10 +896,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
894896
</para>
895897

896898
<para>
897-
Each unique table constraint must name a set of columns that is
899+
Each unique constraint should name a set of columns that is
898900
different from the set of columns named by any other unique or
899-
primary key constraint defined for the table. (Otherwise it
900-
would just be the same constraint listed twice.)
901+
primary key constraint defined for the table. (Otherwise, redundant
902+
unique constraints will be discarded.)
901903
</para>
902904

903905
<para>
@@ -910,10 +912,15 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
910912
<para>
911913
Adding a unique constraint will automatically create a unique btree
912914
index on the column or group of columns used in the constraint.
913-
The optional clause <literal>INCLUDE</literal> adds to that index
914-
one or more columns on which the uniqueness is not enforced.
915-
Note that although the constraint is not enforced on the included columns,
916-
it still depends on them. Consequently, some operations on these columns
915+
</para>
916+
917+
<para>
918+
The optional <literal>INCLUDE</literal> clause adds to that index
919+
one or more columns that are simply <quote>payload</quote>: uniqueness
920+
is not enforced on them, and the index cannot be searched on the basis
921+
of those columns. However they can be retrieved by an index-only scan.
922+
Note that although the constraint is not enforced on included columns,
923+
it still depends on them. Consequently, some operations on such columns
917924
(e.g., <literal>DROP COLUMN</literal>) can cause cascaded constraint and
918925
index deletion.
919926
</para>
@@ -923,7 +930,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
923930
<varlistentry>
924931
<term><literal>PRIMARY KEY</literal> (column constraint)</term>
925932
<term><literal>PRIMARY KEY ( <replaceable class="parameter">column_name</replaceable> [, ... ] )</literal>
926-
<optional> INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...]) </optional> (table constraint)</term>
933+
<optional> <literal>INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...])</literal> </optional> (table constraint)</term>
927934
<listitem>
928935
<para>
929936
The <literal>PRIMARY KEY</literal> constraint specifies that a column or
@@ -941,27 +948,34 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
941948

942949
<para>
943950
<literal>PRIMARY KEY</literal> enforces the same data constraints as
944-
a combination of <literal>UNIQUE</literal> and <literal>NOT NULL</literal>, but
951+
a combination of <literal>UNIQUE</literal> and <literal>NOT
952+
NULL</literal>. However,
945953
identifying a set of columns as the primary key also provides metadata
946954
about the design of the schema, since a primary key implies that other
947955
tables can rely on this set of columns as a unique identifier for rows.
948956
</para>
949957

950958
<para>
951-
<literal>PRIMARY KEY</literal> constraints share the restrictions that
952-
<literal>UNIQUE</literal> constraints have when placed on partitioned
953-
tables.
959+
When placed on a partitioned table, <literal>PRIMARY KEY</literal>
960+
constraints share the restrictions previously decribed
961+
for <literal>UNIQUE</literal> constraints.
954962
</para>
955963

956964
<para>
957965
Adding a <literal>PRIMARY KEY</literal> constraint will automatically
958966
create a unique btree index on the column or group of columns used in the
959-
constraint. The optional <literal>INCLUDE</literal> clause allows a list
960-
of columns to be specified which will be included in the non-key portion
961-
of the index. Although uniqueness is not enforced on the included columns,
962-
the constraint still depends on them. Consequently, some operations on the
963-
included columns (e.g., <literal>DROP COLUMN</literal>) can cause cascaded
964-
constraint and index deletion.
967+
constraint.
968+
</para>
969+
970+
<para>
971+
The optional <literal>INCLUDE</literal> clause adds to that index
972+
one or more columns that are simply <quote>payload</quote>: uniqueness
973+
is not enforced on them, and the index cannot be searched on the basis
974+
of those columns. However they can be retrieved by an index-only scan.
975+
Note that although the constraint is not enforced on included columns,
976+
it still depends on them. Consequently, some operations on such columns
977+
(e.g., <literal>DROP COLUMN</literal>) can cause cascaded constraint and
978+
index deletion.
965979
</para>
966980
</listitem>
967981
</varlistentry>

0 commit comments

Comments
 (0)