As I see in documentation there is a possibility to create gist index which will reject overlapping ranges
CREATE TABLE room_reservation (
room text,
during daterange,
EXCLUDE USING gist (room WITH =, during WITH &&)
);
It works perfect, but how to adjust it to not count infinite range – ‘(,)’ (e.g. range from -inf to inf) as overlapped to anything except self. For example i want to allow adding only one row with infinite bounds and rest date ranges should just use && operator to check.
valid data:
| room | during | | r1 | (,) | | r2 | (10.09.2012, 10.09.2013) | | r2 | (11.09.2013, 11.11.2013 |
and inserting row with during = (01.01.2013, 01.01.2015) will throw and error.
To expand jug’s comment