On Thu, May 10, 2018 at 12:16 PM, Martín Marqués <mar...@2ndquadrant.com>
wrote:

> 2018-05-10 16:04 GMT-03:00 Eugene Wang <eugenewan...@gmail.com>:
> > Unique Constraint and Unique Index should be the same in this
> single-column
> > case, right?
>
> The unique index is what enforces the uniqueness of the field with a
> UNIQUE constraint, but a unique index is not necessarily a constraint.
>

​Specifically, a constraint cannot have a WHERE clause while the index can
(i.e., unique indexes can be partial, unique constraints always cover the
entire table).

Thinking this over I'd probably remove UNIQUE from both existing examples.
I'd then add an example of a partial unique index (especially since we lack
an example of a partial index presently) - and note that non-partial unique
indexes are better implemented by defining a constraint on the relation as
opposed to creating the index explicitly.

David J.
​

Reply via email to