]> begriffs open source - ai-pg/blob - full-docs/txt/indexes-unique.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / indexes-unique.txt
1
2 11.6. Unique Indexes #
3
4    Indexes can also be used to enforce uniqueness of a column's value, or
5    the uniqueness of the combined values of more than one column.
6 CREATE UNIQUE INDEX name ON table (column [, ...]) [ NULLS [ NOT ] DISTINCT ];
7
8    Currently, only B-tree indexes can be declared unique.
9
10    When an index is declared unique, multiple table rows with equal
11    indexed values are not allowed. By default, null values in a unique
12    column are not considered equal, allowing multiple nulls in the column.
13    The NULLS NOT DISTINCT option modifies this and causes the index to
14    treat nulls as equal. A multicolumn unique index will only reject cases
15    where all indexed columns are equal in multiple rows.
16
17    PostgreSQL automatically creates a unique index when a unique
18    constraint or primary key is defined for a table. The index covers the
19    columns that make up the primary key or unique constraint (a
20    multicolumn index, if appropriate), and is the mechanism that enforces
21    the constraint.
22
23 Note
24
25    There's no need to manually create indexes on unique columns; doing so
26    would just duplicate the automatically-created index.