pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frank Bax <fbax@sympatico.ca>
To: pgsql-sql@postgresql.org
Subject: Re: Clever way to check overlapping time intervals ?
Date: Fri, 16 Sep 2011 07:15:03 -0400
Message-ID: <4E732FB7.50009@sympatico.ca> (raw)
In-Reply-To: <4E728CD7.9040505@gmx.net>
References: <4E728CD7.9040505@gmx.net>

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)




view thread (4+ messages)

Message-ID: <4E732FB7.50009@sympatico.ca>
Permalink:  ../4E732FB7.50009@sympatico.ca/
Also on:    postgresql.org/message-id/4E732FB7.50009@sympatico.ca

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: fbax@sympatico.ca
  Subject: Re: Clever way to check overlapping time intervals ?
  In-Reply-To: <4E732FB7.50009@sympatico.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox