Dates overlapping with PostgreSQL

PostgreSQL supports checking if date ranges overlaps with each other (i.e. useful in reservation systems to check if 2 request do not conflict).

It can be used with:

  • dates:

      SELECT *
      FROM bookings
      WHERE (date_start, date_finish) OVERLAPS (DATE '2018-07-12 06:30:00', DATE '2018-07-12 06:40:00');
    
  • intervals:

      SELECT *
      FROM bookings
      (date, INTERVAL '1 sec' * duration) OVERLAPS (DATE '2018-07-12 06:30:00', DATE '2018-07-12 06:40:00');