summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-12-08 13:09:48 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-12-08 13:09:48 -0500
commit14db9579222138b3fba2f73c285ff3f9e4bf9465 (patch)
tree9b5100f450651810beff64d7388dece4a3704e72
parent0921b86ca1e451c70642c3007feb25f7efb34f65 (diff)
downloadpostgresql-14db9579222138b3fba2f73c285ff3f9e4bf9465.tar.gz
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
-rw-r--r--doc/src/sgml/ref/create_table.sgml22
1 files changed, 15 insertions, 7 deletions
diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml
index 27a999c71b..c169d61584 100644
--- a/doc/src/sgml/ref/create_table.sgml
+++ b/doc/src/sgml/ref/create_table.sgml
@@ -492,9 +492,11 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
<para>
The <literal>UNIQUE</literal> constraint specifies that a
group of one or more columns of a table can contain
- only unique values. The behavior of the unique table constraint
- is the same as that for column constraints, with the additional
- capability to span multiple columns.
+ only unique values. The behavior of a unique table constraint
+ is the same as that of a unique column constraint, with the
+ additional capability to span multiple columns. The constraint
+ therefore enforces that any two rows must differ in at least one
+ of these columns.
</para>
<para>
@@ -503,10 +505,10 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
</para>
<para>
- Each unique table constraint must name a set of columns that is
+ Each unique constraint should name a set of columns that is
different from the set of columns named by any other unique or
- primary key constraint defined for the table. (Otherwise it
- would just be the same constraint listed twice.)
+ primary key constraint defined for the table. (Otherwise, redundant
+ unique constraints will be discarded.)
</para>
</listitem>
</varlistentry>
@@ -531,11 +533,17 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
<para>
<literal>PRIMARY KEY</literal> enforces the same data constraints as
- a combination of <literal>UNIQUE</> and <literal>NOT NULL</>, but
+ a combination of <literal>UNIQUE</> and <literal>NOT NULL</>. However,
identifying a set of columns as the primary key also provides metadata
about the design of the schema, since a primary key implies that other
tables can rely on this set of columns as a unique identifier for rows.
</para>
+
+ <para>
+ Adding a <literal>PRIMARY KEY</literal> constraint will automatically
+ create a unique btree index on the column or group of columns used in the
+ constraint.
+ </para>
</listitem>
</varlistentry>