Re: Unique Constraint Based on Date Range - Mailing list pgsql-sql

From Manfred Koizar
Subject Re: Unique Constraint Based on Date Range
Date
Msg-id 0hetmvk1gcl1nlhg710hevr1g7tk7998v2@email.aon.at
Whole thread Raw
In response to Re: Unique Constraint Based on Date Range  (Kevin Houle <kevin@houle.org>)
List pgsql-sql
On Sat, 20 Sep 2003 18:55:34 -0400, Kevin Houle <kevin@houle.org>
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
 

TryWHERE 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
 

ServusManfred


pgsql-sql by date:

Previous
From: "Kumar"
Date:
Subject: Backup error - Pls help
Next
From: Richard Huxton
Date:
Subject: Re: Backup error - Pls help