How to create unique index on multiple columns where the combination doesn't matter?

From: Glen Huang <hey(dot)hgl(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How to create unique index on multiple columns where the combination doesn't matter?
Date: 2017-03-22 16:54:34
Message-ID: 27CF1813-7E38-4928-8566-A24E7D45BAF2@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

If I have a table like

CREATE TABLE relationship (
obj1 INTEGER NOT NULL REFERENCES object,
obj2 INTEGER NOT NULL REFERENCES object,
obj3 INTEGER NOT NULL REFERENCES object,
...
)

And I want to constrain that if 1,2,3 is already in the table, rows like 1,3,2 or 2,1,3 shouldn't be allowed.

Is there a general solution to this problem?

Sorry if the question is too basic, but I couldn't find the answer in the doc, at least not in the chapter on unique index.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2017-03-22 17:04:46 Re: How to create unique index on multiple columns where the combination doesn't matter?
Previous Message Alexander Farber 2017-03-22 15:15:23 Re: COPY ... FROM stdin WITH FORMAT csv