Re: Constraint Problem - Mailing list pgsql-general

From Greg Stark
Subject Re: Constraint Problem
Date
Msg-id 87brrs58oa.fsf@stark.dyndns.tv
Whole thread Raw
In response to Re: Constraint Problem  (Ron St-Pierre <rstpierre@syscor.com>)
List pgsql-general
Ron St-Pierre <rstpierre@syscor.com> writes:

> No it doesn't. For example, after I create the unique index I can still input:
>     company10     association7     true
>     company10     association7     true
>     company10     association7     true
> I want to prevent this from happening, but still allow multiple
>     company10     association7     false
>     company10     association7     false
> entries for example.

For example:

test=# create table test (company integer, association integer, isdefault boolean);
CREATE TABLE
test=# create unique index testi on (company,association) where isdefault;
ERROR:  syntax error at or near "(" at character 30
test=# create unique index testi on test (company,association) where isdefault;
CREATE INDEX
test=# insert into test values (10,7,true);
INSERT 6888594 1
test=# insert into test values (10,7,true);
ERROR:  duplicate key violates unique constraint "testi"
test=# insert into test values (10,7,false);
INSERT 6888596 1
test=# insert into test values (10,7,false);
INSERT 6888597 1
test=# select * from test;
 company | association | isdefault
---------+-------------+-----------
      10 |           7 | t
      10 |           7 | f
      10 |           7 | f
(3 rows)

--
greg

pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: PostgreSQL v7.4 Release Candidate 1
Next
From: Peter Eisentraut
Date:
Subject: Re: PostgreSQL v7.4 Release Candidate 1