PostgreSQL's OVERLAPS operator is not fully inclusive

Updated . Posted . Visible to the public.

PostgreSQL supports the SQL OVERLAPS operator. You can use it to test if two date ranges overlap:

=> SELECT ('2001-02-16'::date, '2001-12-21'::date) OVERLAPS
          ('2001-12-20'::date, '2002-10-30'::date);

overlaps
--------
true

An important caveat is that the date ranges are defined as start <= time < end. As such the later date is not included in the range:

=> SELECT ('2001-02-16'::date, '2001-12-21'::date) OVERLAPS
          ('2001-12-21'::date, '2002-10-30'::date);

overlaps
--------
false

Also compare our card Test if two date ranges overlap in Ruby or Rails.

Henning Koch
Last edit
Tobias Kraze
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2017-10-27 15:29)