Placing a uniqueness constraint on a date range
4
votes
1
answer
2572
views
I have a table
reservation
with columns roomno(INTEGER)
, startdate(DATE)
, enddate(DATE)
with a primary key on (roomno, startdate
).
How do I place a constraint on the table such that bookings are not allowed to overlap?
I am trying to implement this in SQLFIDDLE postgreSQL9.3
For example:
101 2016-01-01 2016-01-05
101 2016-01-03 2016-01-06 [This row should not be possible to insert]
startdate
and enddate
are data type date
.
Asked by srip
(143 rep)
May 31, 2016, 04:56 PM
Last activity: Jan 7, 2024, 11:33 PM
Last activity: Jan 7, 2024, 11:33 PM