Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id C1F4BB5DC5B for ; Fri, 16 Sep 2011 08:38:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 04349-06 for ; Fri, 16 Sep 2011 11:38:24 +0000 (UTC) X-Greylist: delayed 00:23:15.642509 by SQLgrey-1.8.0-rc2 Received: from hapkido.dreamhost.com (hapkido.dreamhost.com [66.33.216.122]) by mail.postgresql.org (Postfix) with ESMTP id 9DD81B5DC60 for ; Fri, 16 Sep 2011 08:38:24 -0300 (ADT) Received: from homiemail-a21.g.dreamhost.com (mailbigip.dreamhost.com [208.97.132.5]) by hapkido.dreamhost.com (Postfix) with ESMTP id F3460184261 for ; Fri, 16 Sep 2011 04:15:08 -0700 (PDT) Received: from homiemail-a21.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTP id CC83530006C for ; Fri, 16 Sep 2011 04:15:05 -0700 (PDT) Received: from t60p.bax.ca (24-246-18-38.cable.teksavvy.com [24.246.18.38]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: fbax@uoglobal.net) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTPSA id 94130300064 for ; Fri, 16 Sep 2011 04:15:05 -0700 (PDT) Message-ID: <4E732FB7.50009@sympatico.ca> Date: Fri, 16 Sep 2011 07:15:03 -0400 From: Frank Bax User-Agent: Mozilla/5.0 (X11; U; OpenBSD amd64; en-US; rv:1.9.2.13) Gecko/20110223 Thunderbird/3.1.7 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Clever way to check overlapping time intervals ? References: <4E728CD7.9040505@gmx.net> In-Reply-To: <4E728CD7.9040505@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201109/35 X-Sequence-Number: 35835 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)