pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Manfred Koizar <mkoi-pg@aon.at>
To: Kevin Houle <kevin@houle.org>
Cc: Andrew Milne <amilne@solutioninc.com>
Cc: 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> (raw)
In-Reply-To: <3F6CDAE6.5010407@houle.org>
References: <3F69FC7F.1040103@solutioninc.com>
	<3F6CDAE6.5010407@houle.org>

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

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



view thread (3+ messages)

Message-ID: <0hetmvk1gcl1nlhg710hevr1g7tk7998v2@email.aon.at>
Permalink:  ../0hetmvk1gcl1nlhg710hevr1g7tk7998v2@email.aon.at/
Also on:    postgresql.org/message-id/0hetmvk1gcl1nlhg710hevr1g7tk7998v2@email.aon.at

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: mkoi-pg@aon.at, kevin@houle.org, amilne@solutioninc.com
  Subject: Re: Unique Constraint Based on Date Range
  In-Reply-To: <0hetmvk1gcl1nlhg710hevr1g7tk7998v2@email.aon.at>
  References: <3F69FC7F.1040103@solutioninc.com> <3F6CDAE6.5010407@houle.org> <0hetmvk1gcl1nlhg710hevr1g7tk7998v2@email.aon.at>

* 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