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°