I have the following constraint:
ALTER TABLE my_table
ADD CONSTRAINT no_overlap EXCLUDE USING gist (
product_id WITH =,
applicable_period WITH &&
)
Now I realized, that this should only be checked conditionally, e.g.
ALTER TABLE my_table
ADD CONSTRAINT no_overlap EXCLUDE USING gist (
product_id WITH =,
applicable_period WITH &&
)
WHERE my_table.user_id IS NULL
Is this possible and otherwise how can I achieve this in an efficient/advised way? (I could add a trigger, but I hope there is more elegant/efficient approaches).
Should I resort to table partition? Thank you
user_id WITH =to your constraint definition.NULLis not equal toNULL?