I have a table in a Postgres DB where col1 and col2 are foreign keys referring to the same column. I want only unique combinations of (col1, col2), i.e. if (1,2) is entered then (2,1) should be rejected. How can I achieve that?
My table definition:
CREATE TABLE mytable (
id serial primary key,
col1 int NOT NULL,
col2 int NOT NULL,
unique (col1, col2)
)
jsonbvalue with a JSON array that is sorted internally automatically. – Erwin Brandstetter Jun 28 '15 at 23:47