Re: unique index with bool

From: Richard Huxton <dev(at)archonet(dot)com>
To: tmpmac(at)mac(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: unique index with bool
Date: 2005-05-19 15:18:09
Message-ID: 428CAE31.8010702@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

tmpmac(at)mac(dot)com wrote:
> CREATE UNIQUE INDEX name on table(param1,param2);
>
> How to create such unique index when param2 is bool type, and this
> param2 should be accepted only in case of true ?
>
> I tried: CREATE UNIQUE INDEX name on table(param1,(param2 = 'true'));
> but it's not working.

Something like:

CREATE UNIQUE INDEX my_uniq_idx ON table(param1,param2)

ALTER TABLE table ADD CONSTRAINT my_constraint CHECK (param2='' OR
param1=true);

So - separate out the test linking param1/param2 from your uniqueness
requirement.
--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-05-19 15:20:27 Re: Postgresql 7.4.7 docs(PDF)
Previous Message Tom Lane 2005-05-19 15:14:09 Re: error explanation