Reputation: 1691
I have a table looking like this:
id bigint,
user_id bigint,
main boolean,
...
Of all entries with same user_id
only one can have main = true
.
Please, advice, how to realize it?
Upvotes: 0
Views: 45
Reputation: 6723
You can use a partial index.
CREATE UNIQUE INDEX index_name ON table_name (user_id) WHERE main;
Upvotes: 3