Re: Date interval overlaps - Mailing list pgsql-novice

From Tom Lane
Subject Re: Date interval overlaps
Date
Msg-id 26756.1251408080@sss.pgh.pa.us
Whole thread Raw
In response to Date interval overlaps  (Ruzsinszky Attila <ruzsinszky.attila@gmail.com>)
Responses Re: Date interval overlaps  (Ruzsinszky Attila <ruzsinszky.attila@gmail.com>)
List pgsql-novice
Ruzsinszky Attila <ruzsinszky.attila@gmail.com> writes:
> select (date '2009-08-23', date '2009-08-31') overlaps (date
> '2009-08-31', date '2009-08-31');

> I want testing whether a given date is in an interval.
> Why did I get false?

The SQL spec says that an exact match on ending endpoint isn't an overlap.
In particular, SQL92 defines the result of OVERLAPS as

              ( S1 > S2 AND NOT ( S1 >= T2 AND T1 >= T2 ) )
              OR
              ( S2 > S1 AND NOT ( S2 >= T1 AND T2 >= T1 ) )
              OR
              ( S1 = S2 AND ( T1 <> T2 OR T1 = T2 ) )

where S1,T1 are the smaller and larger endpoints of the first interval
and similarly for S2,T2.  You've got S2 > S1, so the middle line
applies, but S2 = T1 and T2 = T1 so the result is false.

            regards, tom lane

pgsql-novice by date:

Previous
From: Ruzsinszky Attila
Date:
Subject: Date interval overlaps
Next
From: "A. Kretschmer"
Date:
Subject: Re: how can I finish my suscription?