Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 07A3EB5DBF0 for ; Thu, 15 Sep 2011 20:40:15 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 13898-04 for ; Thu, 15 Sep 2011 23:40:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id 7F35FB5DBCB for ; Thu, 15 Sep 2011 20:40:01 -0300 (ADT) Received: (qmail invoked by alias); 15 Sep 2011 23:40:00 -0000 Received: from mue-88-130-49-082.dsl.tropolys.de (EHLO [192.168.1.113]) [88.130.49.82] by mail.gmx.net (mp072) with SMTP; 16 Sep 2011 01:40:00 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX1/6stRo73b6/ubWkI653jU/VhUiZXp7op5lt497eY 4NROs04DZzPDY/ Message-ID: <4E728CD7.9040505@gmx.net> Date: Fri, 16 Sep 2011 01:40:07 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: "pgsql-sql@postgresql.org" Subject: Clever way to check overlapping time intervals ? Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.403 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/32 X-Sequence-Number: 35832 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.