Re: [GENERAL] Help with exclusion constraint

2014-03-28 Thread Igor Neyman
From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general-ow...@postgresql.org] On Behalf Of Moshe Jacobson Sent: Friday, March 28, 2014 10:31 AM To: pgsql-general Subject: [GENERAL] Help with exclusion constraint Take the following table: CREATE TABLE exclusion_example AS ( pk_col i

Re: [GENERAL] Help with exclusion constraint

2014-03-28 Thread Moshe Jacobson
On Fri, Mar 28, 2014 at 12:21 PM, Igor Neyman wrote: > For this: > "any given value of fk_col that there is a maximum of one row with > bool_col = true." > > why don't you (instead) create partial unique index: > CREATE UNIQUE INDEX on exclusion_example(fk_col, bool_col) WHERE bool_col > IS TRUE;

Re: [GENERAL] Help with exclusion constraint

2014-03-28 Thread Moshe Jacobson
On Fri, Mar 28, 2014 at 12:45 PM, wrote: > > 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); Yes

Re: [GENERAL] Help with exclusion constraint

2014-03-28 Thread hari . fuchs
Moshe Jacobson 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 max