16

Does creating a unique constraint on a Postgres column remove the need to index it?

I expect that an index is automatically needed to maintain the constraint efficiently.

MDCCL
8,5303 gold badges32 silver badges63 bronze badges
asked Mar 22, 2016 at 0:06

1 Answer 1

21

Yes. A UNIQUE constraint is implemented with the help of a unique index - a b-tree index with default ascending sort ordering over all involved columns. The index is created and maintained automatically, and is used for all purposes like a plain unique index by Postgres.

There is no need to create another (redundant) unique index like it, that would be a waste of resources.

Detailed explanation:

Some rare exceptions apply for multicolumn indexes with special sort options:

answered Mar 22, 2016 at 0:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.