Answer the question
In order to leave comments, you need to log in
Postgresql Exclusion constraints, want something weird?
Good afternoon colleagues.
There is a table:
CREATE TABLE test_good
(
id BIGINT PRIMARY KEY NOT NULL,
good_id UUID DEFAULT uuid_generate_v4() NOT NULL,
by_default BOOLEAN DEFAULT false NOT NULL,
);
Answer the question
In order to leave comments, you need to log in
Somehow this is not very in the spirit of relational databases. You can for example create a defaults table with group_id(unique) and default_item_id if one or no item can be selected for the group.
CREATE UNIQUE INDEX test_good_default_goods ON test_good (good_id)
WHERE by_default = true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question