- use
TIMESTAMP WITH TIME ZONE
forhall_schedule
'sstart
andend
time points use
tstzrange
to detect overlappings, like:SELECT * FROM "hall_schedule" WHERE NOT (tstzrange("start", "end", '[]') && tstzrange(:input_start, :input_end, '[]'))
Notes:
- you could store the whole range in a
tstzrange
column within thehall_schedule
table, if you want, but it's harder to edit from the application (you must supply its text representation everywhere) - this way, you can actually create
EXCLUDE
constraints too, to prevent events inhall_schedule
to overlap each other, if you want.
Update:
Additionally, to speed up your queries, you can add the following index too:
CREATE INDEX "hall_schedule_range_idx"
ON "hall_schedule"
USING gist ((tstzrange("start", "end", '[]')));