Let's suppose a table:
CREATE TABLE foo (
id serial primary key
, range int4range NOT NULL
, barid integer references bar(id)
, baz whatever... NOT NULL
, EXCLUDE USING gist (range WITH &&, barid WITH =)
);
The exclusion constraint is supposed to not allow overlapping "range" values for the same "barid" value. But I would like it to treat "NULL" just like other values (so not allow overlappig ranges for diffrent records having barid = NULL). So given a = NULL and b = NULL, I would like to achieve "a IS NOT DISTINCT FROM b" type of behaviour , instead of "a = b" one (as described here). Does such an operator exist? At the moment I am able to achieve that only by using
EXCLUDE USING gist (range WITH &&, COALESCE(barid, -1) WITH =)