Re: Non-Overlaping date interval index

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Pailloncy Jean-Gerard <jg(at)rilk(dot)com>
Cc: Postgres list general mailing <pgsql-general(at)postgresql(dot)org>
Subject: Re: Non-Overlaping date interval index
Date: 2006-02-18 09:18:23
Message-ID: 20060218091823.GC20716@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Feb 18, 2006 at 10:03:11AM +0100, Pailloncy Jean-Gerard wrote:
> Hi,
>
> I wonder how to have a sort of "uniq" index on date interval, such
> that there is no date interval overlaping in the table.
>
> exemple:
> create table test (start timestamp, end timestamp);
> with the constraint: end > start

Unfortunatly no. There have been discussions about extending unique
indexes to something other than just single values but no code has been
produced yet.

You can get fairly close with a trigger though (not syntactically
correct):

create function range_check() returns trigger as $$
if exists( select 1 from test
where (new.start < start) <> (new.end > end) then
raise error 'Conflict'
return NEW;
$$;

create trigger blah on insert or update to test do range_check();

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2006-02-18 09:31:35 Re: Non-Overlaping date interval index
Previous Message Pailloncy Jean-Gerard 2006-02-18 09:03:11 Non-Overlaping date interval index