Re: Help with exclusion constraint

From: hari(dot)fuchs(at)gmail(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Help with exclusion constraint
Date: 2014-03-28 16:45:16
Message-ID: 87ppl6e0gz.fsf@hf.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Moshe Jacobson <moshe(at)neadwerx(dot)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);

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Moshe Jacobson 2014-03-28 16:59:17 Re: Help with exclusion constraint
Previous Message Igor Neyman 2014-03-28 16:21:10 Re: Help with exclusion constraint