3 ms·
Range types combined with exclusion constraints solve the problem of not allowing overlapping bookings using a database constraint. The solution is simple, clea
by jeltz 14y ago
Range types combined with exclusion constraints solve the problem of not allowing overlapping bookings using a database constraint. The solution is simple, clean, and flexible unlike the workarounds.
Example of adding such a constraint:
ALTER TABLE reservation ADD EXCLUDE USING gist (room WITH =, during WITH &&);
In this example a room cannot be double booked.
EDIT: This is a feature entirely unique to PostgreSQL.
- jeffdavis 14y agoI'll be speaking on this use case next week at Postgres Open ( http://postgresopen.org http://postgresopen.org ) as part of a larger demo of temporal databases in postgresql. Jonathan S. Katz will also be presenting on Range Types.