Created
September 6, 2012 12:18
-
-
Save pfote/3655665 to your computer and use it in GitHub Desktop.
postgres .. unique index on two fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test=# create table j (id1 int, id2 int); | |
CREATE TABLE | |
test=*# create unique index idx_j on j(greatest(id1, id2), least(id1, id2)); | |
CREATE INDEX | |
test=*# insert into j values (1,2); | |
INSERT 0 1 | |
test=*# insert into j values (2,1); | |
ERROR: duplicate key violates unique constraint "idx_j" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment