I need a data structure that can store non-overlapping ranges within a single dimension. The entire range of the dimension need not be completely covered.
An example
If you are lucky (!) enough to be using Postgres, you can use a tstzrange
column, and apply a constraint to prevent overlaps. The bonus of using a range type is that it will inherently prevent start being greater than finish.
ALTER TABLE "booking"
ADD CONSTRAINT "overlapping_bookings"
EXCLUDE USING gist ("period" WITH &&, "room" WITH =);
You may need to CREATE EXTENSION IF NOT EXISTS btree_gist
, as creating a gist using && is not supported without that extension.