Re: Help with exclusion constraint - Mailing list pgsql-general

From hari.fuchs@gmail.com
Subject Re: Help with exclusion constraint
Date
Msg-id 87ppl6e0gz.fsf@hf.protecting.net
Whole thread Raw
In response to Help with exclusion constraint  (Moshe Jacobson <moshe@neadwerx.com>)
Responses Re: Help with exclusion constraint  (Moshe Jacobson <moshe@neadwerx.com>)
List pgsql-general
Moshe Jacobson <moshe@neadwerx.com> writes:

> Take the following table:
>
> CREATE TABLE exclusion_example AS
> (
>      pk_col  integer primary key,
>      fk_col integer not null references other_table,
>      bool_col boolean not null
> );
>
> I want to ensure that for any given value of fk_col that there is a maximum
> of one row with bool_col = true.

This should be what you want:

ALTER TABLE exclusion_example
ADD CONSTRAINT ex
EXCLUDE (fk_col WITH =) WHERE (bool_col);

pgsql-general by date:

Previous
From: Igor Neyman
Date:
Subject: Re: Help with exclusion constraint
Next
From: Moshe Jacobson
Date:
Subject: Re: Help with exclusion constraint