Need help writing exclusion constraint - Mailing list pgsql-general

From Matthew Wilson
Subject Need help writing exclusion constraint
Date
Msg-id igsrss$3a5$1@dough.gmane.org
Whole thread Raw
Responses Re: Need help writing exclusion constraint  (Daniel Popowich <danielpopowich@gmail.com>)
Re: Need help writing exclusion constraint  (Andreas Kretschmer <akretschmer@spamfence.net>)
Re: Need help writing exclusion constraint  (Jeff Davis <pgsql@j-davis.com>)
List pgsql-general
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.

Thanks in advance.

Matt

pgsql-general by date:

Previous
From: "Andrus Moor"
Date:
Subject: Re: How to generate unique invoice numbers foreach day
Next
From: Jorge Godoy
Date:
Subject: Re: How to generate unique invoice numbers foreach day