11.6. Unique Indexes

Note: The following description applies only to Postgres-XC

In Postgres-XC, for distributed table, unique index is allowed only for the distribution column. For replicated tables, there's no such restriction.

Note: The following description applies both to Postgres-XC and PostgreSQL if not described explicitly.

Indexes can also be used to enforce uniqueness of a column's value, or the uniqueness of the combined values of more than one column.

CREATE UNIQUE INDEX name ON table (column [, ...]);

Currently, only B-tree indexes can be declared unique.

When an index is declared unique, multiple table rows with equal indexed values are not allowed. Null values are not considered equal. A multicolumn unique index will only reject cases where all indexed columns are equal in multiple rows.

Postgres-XC automatically creates a unique index when a unique constraint or primary key is defined for a table. The index covers the columns that make up the primary key or unique constraint (a multicolumn index, if appropriate), and is the mechanism that enforces the constraint.

Note: The preferred way to add a unique constraint to a table is ALTER TABLE ... ADD CONSTRAINT. The use of indexes to enforce unique constraints could be considered an implementation detail that should not be accessed directly. One should, however, be aware that there's no need to manually create indexes on unique columns; doing so would just duplicate the automatically-created index.

Postgres-XC supports constraints only enforceable locally. You should not specify any constraint which need to refer to rows at remote node.