Re: Clever way to check overlapping time intervals ?

From: Frank Bax <fbax(at)sympatico(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Clever way to check overlapping time intervals ?
Date: 2011-09-16 11:15:03
Message-ID: 4E732FB7.50009@sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 09/15/11 19:40, Andreas wrote:
> Hi,
> is there a clever way to check overlapping time intervals ?
> An option named n should be taken from date y to y.
> The same name is ok for another interval.
>
> e.g. table : mytab ( d1 date, d2 date, n text, v text )
>
> There should be a constraint to provide no row can have a d1 or d2
> within the interval of another row in case they have the same n.
>
> And no row can have an interval that encloses an existing interval.
>

self join with "OVERLAPS" operator:

select t1.*,t2.* from (select * from mytab) as t1
full join (select * from mytab) as t2
where (t1.d1,t1.d2) overlaps (t2.d1,t2.d2)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tim Landscheidt 2011-09-16 23:55:57 Re: Window function sort order help
Previous Message pasman pasmański 2011-09-16 09:17:25 Re: Clever way to check overlapping time intervals ?