Should I specify both INDEX and UNIQUE INDEX?

Posted by Matt Huggins on Stack Overflow See other posts from Stack Overflow or by Matt Huggins
Published on 2010-12-25T21:07:25Z Indexed on 2010/12/27 6:54 UTC
Read the original article Hit count: 276

On one of my PostgreSQL tables, I have a set of two fields that will be defined as being unique in the table, but will also both be used together when selecting data. Given this, do I only need to define a UNIQUE INDEX, or should I specify an INDEX in addition to the UNIQUE INDEX?

This?

CREATE UNIQUE INDEX mytable_col1_col2_idx ON mytable (col1, col2);

Or this?

CREATE UNIQUE INDEX mytable_col1_col2_uidx ON mytable (col1, col2);
CREATE INDEX mytable_col1_col2_idx ON mytable (col1, col2);

© Stack Overflow or respective owner

Related posts about postgresql

Related posts about indexing