Re: Need help writing exclusion constraint - Mailing list pgsql-general

From Andreas Kretschmer
Subject Re: Need help writing exclusion constraint
Date
Msg-id 20110116135944.GA9617@tux
Whole thread Raw
In response to Need help writing exclusion constraint  (Matthew Wilson <matt@tplus1.com>)
List pgsql-general
Matthew Wilson <matt@tplus1.com> wrote:

> I have a table like this:
>
> create table event(
>
>     destination_id integer not null references destination
>     (destination_id),
>
>     starts timestamp,
>     ends timestamp
> );
>
> I want to make sure that no two rows **with the same destination_id**
> overlap in time.
>
> I'm not sure how to write this exclusion constraint.  I know how to make
> the constraint to prevent any two rows from overlapping, but I want to
> allow rows to overlap as long as they don't have the same
> destination_id.

If I where you, i would use the temporal data typ ;-)

It's a new extension for PostgreSQL, see here:
http://temporal.projects.postgresql.org/reference.html,
http://thoughts.j-davis.com/2010/09/25/exclusion-constraints-are-generalized-sql-unique/
http://www.slideshare.net/pgconf/not-just-unique-exclusion-constraints


Regards, Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

pgsql-general by date:

Previous
From: Dmitriy Igrishin
Date:
Subject: Re: Why can't I change a password
Next
From: Вячеслав Блинников
Date:
Subject: libpq: binary data vs textual