Re: Date interval overlaps

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ruzsinszky Attila <ruzsinszky(dot)attila(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Date interval overlaps
Date: 2009-08-27 21:21:20
Message-ID: 26756.1251408080@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Ruzsinszky Attila <ruzsinszky(dot)attila(at)gmail(dot)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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Andrew Maracini 2009-08-27 22:18:34 installing Postgres 8.3 on Mac
Previous Message Ruzsinszky Attila 2009-08-27 20:56:58 Date interval overlaps