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

Commit e824ddc

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 101c8ae commit e824ddc

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
@@ -866,15 +866,17 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
866866
<varlistentry>
867867
<term><literal>UNIQUE</literal> (column constraint)</term>
868868
<term><literal>UNIQUE ( <replaceable class="parameter">column_name</replaceable> [, ... ] )</literal>
869-
<optional> INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...]) </optional> (table constraint)</term>
869+
<optional> <literal>INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...])</literal> </optional> (table constraint)</term>
870870

871871
<listitem>
872872
<para>
873873
The <literal>UNIQUE</literal> constraint specifies that a
874874
group of one or more columns of a table can contain
875-
only unique values. The behavior of the unique table constraint
876-
is the same as that for column constraints, with the additional
877-
capability to span multiple columns.
875+
only unique values. The behavior of a unique table constraint
876+
is the same as that of a unique column constraint, with the
877+
additional capability to span multiple columns. The constraint
878+
therefore enforces that any two rows must differ in at least one
879+
of these columns.
878880
</para>
879881

880882
<para>
@@ -883,10 +885,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
883885
</para>
884886

885887
<para>
886-
Each unique table constraint must name a set of columns that is
888+
Each unique constraint should name a set of columns that is
887889
different from the set of columns named by any other unique or
888-
primary key constraint defined for the table. (Otherwise it
889-
would just be the same constraint listed twice.)
890+
primary key constraint defined for the table. (Otherwise, redundant
891+
unique constraints will be discarded.)
890892
</para>
891893

892894
<para>
@@ -899,10 +901,15 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
899901
<para>
900902
Adding a unique constraint will automatically create a unique btree
901903
index on the column or group of columns used in the constraint.
902-
The optional clause <literal>INCLUDE</literal> adds to that index
903-
one or more columns on which the uniqueness is not enforced.
904-
Note that although the constraint is not enforced on the included columns,
905-
it still depends on them. Consequently, some operations on these columns
904+
</para>
905+
906+
<para>
907+
The optional <literal>INCLUDE</literal> clause adds to that index
908+
one or more columns that are simply <quote>payload</quote>: uniqueness
909+
is not enforced on them, and the index cannot be searched on the basis
910+
of those columns. However they can be retrieved by an index-only scan.
911+
Note that although the constraint is not enforced on included columns,
912+
it still depends on them. Consequently, some operations on such columns
906913
(e.g., <literal>DROP COLUMN</literal>) can cause cascaded constraint and
907914
index deletion.
908915
</para>
@@ -912,7 +919,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
912919
<varlistentry>
913920
<term><literal>PRIMARY KEY</literal> (column constraint)</term>
914921
<term><literal>PRIMARY KEY ( <replaceable class="parameter">column_name</replaceable> [, ... ] )</literal>
915-
<optional> INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...]) </optional> (table constraint)</term>
922+
<optional> <literal>INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...])</literal> </optional> (table constraint)</term>
916923
<listitem>
917924
<para>
918925
The <literal>PRIMARY KEY</literal> constraint specifies that a column or
@@ -930,27 +937,34 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
930937

931938
<para>
932939
<literal>PRIMARY KEY</literal> enforces the same data constraints as
933-
a combination of <literal>UNIQUE</literal> and <literal>NOT NULL</literal>, but
940+
a combination of <literal>UNIQUE</literal> and <literal>NOT
941+
NULL</literal>. However,
934942
identifying a set of columns as the primary key also provides metadata
935943
about the design of the schema, since a primary key implies that other
936944
tables can rely on this set of columns as a unique identifier for rows.
937945
</para>
938946

939947
<para>
940-
<literal>PRIMARY KEY</literal> constraints share the restrictions that
941-
<literal>UNIQUE</literal> constraints have when placed on partitioned
942-
tables.
948+
When placed on a partitioned table, <literal>PRIMARY KEY</literal>
949+
constraints share the restrictions previously decribed
950+
for <literal>UNIQUE</literal> constraints.
943951
</para>
944952

945953
<para>
946954
Adding a <literal>PRIMARY KEY</literal> constraint will automatically
947955
create a unique btree index on the column or group of columns used in the
948-
constraint. The optional <literal>INCLUDE</literal> clause allows a list
949-
of columns to be specified which will be included in the non-key portion
950-
of the index. Although uniqueness is not enforced on the included columns,
951-
the constraint still depends on them. Consequently, some operations on the
952-
included columns (e.g., <literal>DROP COLUMN</literal>) can cause cascaded
953-
constraint and index deletion.
956+
constraint.
957+
</para>
958+
959+
<para>
960+
The optional <literal>INCLUDE</literal> clause adds to that index
961+
one or more columns that are simply <quote>payload</quote>: uniqueness
962+
is not enforced on them, and the index cannot be searched on the basis
963+
of those columns. However they can be retrieved by an index-only scan.
964+
Note that although the constraint is not enforced on included columns,
965+
it still depends on them. Consequently, some operations on such columns
966+
(e.g., <literal>DROP COLUMN</literal>) can cause cascaded constraint and
967+
index deletion.
954968
</para>
955969
</listitem>
956970
</varlistentry>

0 commit comments

Comments
 (0)