X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 3B56AD1CA0E for ; Mon, 22 Sep 2003 09:12:46 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 86582-03 for ; Mon, 22 Sep 2003 06:12:17 -0300 (ADT) Received: from email05.aon.at (WARSL402PIP4.highway.telekom.at [195.3.96.79]) by svr1.postgresql.org (Postfix) with SMTP id BC4E0D1C9EC for ; Mon, 22 Sep 2003 06:12:13 -0300 (ADT) Received: (qmail 42790 invoked from network); 22 Sep 2003 09:12:08 -0000 Received: from m170p004.dipool.highway.telekom.at (HELO cantor) ([62.46.11.36]) (envelope-sender ) by qmail5rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 22 Sep 2003 09:12:08 -0000 From: Manfred Koizar To: Kevin Houle Cc: Andrew Milne , pgsql-sql@postgresql.org Subject: Re: Unique Constraint Based on Date Range Date: Mon, 22 Sep 2003 11:14:37 +0200 Message-ID: <0hetmvk1gcl1nlhg710hevr1g7tk7998v2@email.aon.at> References: <3F69FC7F.1040103@solutioninc.com> <3F6CDAE6.5010407@houle.org> In-Reply-To: <3F6CDAE6.5010407@houle.org> X-Mailer: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/244 X-Sequence-Number: 15222 On Sat, 20 Sep 2003 18:55:34 -0400, Kevin Houle wrote: > SELECT INTO result * FROM table_rates WHERE > effective_date >= NEW.effective_date AND > expiry_date <= NEW.expiry_date AND > cost = NEW.cost; > IF FOUND THEN > RAISE EXCEPTION ''record overlaps with existing record''; > END IF; This only catches complete inclusion of an old range in the new one. new b---------------------e old b--------------e Try WHERE effective_date < NEW.expiry_date AND expiry_date > NEW.effective_date which also detects new b--------------------e old b-------------------e old b------------------e old b--------------------------------e Servus Manfred