Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2bf5d1a

Browse filesBrowse 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 3410a9b commit 2bf5d1a
Copy full SHA for 2bf5d1a

File tree

Expand file treeCollapse file tree

1 file changed

+15
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-7
lines changed

‎doc/src/sgml/ref/create_table.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/ref/create_table.sgml
+15-7Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,11 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
492492
<para>
493493
The <literal>UNIQUE</literal> constraint specifies that a
494494
group of one or more columns of a table can contain
495-
only unique values. The behavior of the unique table constraint
496-
is the same as that for column constraints, with the additional
497-
capability to span multiple columns.
495+
only unique values. The behavior of a unique table constraint
496+
is the same as that of a unique column constraint, with the
497+
additional capability to span multiple columns. The constraint
498+
therefore enforces that any two rows must differ in at least one
499+
of these columns.
498500
</para>
499501

500502
<para>
@@ -503,10 +505,10 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
503505
</para>
504506

505507
<para>
506-
Each unique table constraint must name a set of columns that is
508+
Each unique constraint should name a set of columns that is
507509
different from the set of columns named by any other unique or
508-
primary key constraint defined for the table. (Otherwise it
509-
would just be the same constraint listed twice.)
510+
primary key constraint defined for the table. (Otherwise, redundant
511+
unique constraints will be discarded.)
510512
</para>
511513
</listitem>
512514
</varlistentry>
@@ -531,11 +533,17 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
531533

532534
<para>
533535
<literal>PRIMARY KEY</literal> enforces the same data constraints as
534-
a combination of <literal>UNIQUE</> and <literal>NOT NULL</>, but
536+
a combination of <literal>UNIQUE</> and <literal>NOT NULL</>. However,
535537
identifying a set of columns as the primary key also provides metadata
536538
about the design of the schema, since a primary key implies that other
537539
tables can rely on this set of columns as a unique identifier for rows.
538540
</para>
541+
542+
<para>
543+
Adding a <literal>PRIMARY KEY</literal> constraint will automatically
544+
create a unique btree index on the column or group of columns used in the
545+
constraint.
546+
</para>
539547
</listitem>
540548
</varlistentry>
541549

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.