Re: Need help writing exclusion constraint

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Need help writing exclusion constraint
Date: 2011-01-16 13:59:44
Message-ID: 20110116135944.GA9617@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Matthew Wilson <matt(at)tplus1(dot)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°

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Вячеслав Блинников 2011-01-16 14:13:01 libpq: binary data vs textual
Previous Message Dmitriy Igrishin 2011-01-16 11:21:28 Re: Why can't I change a password