From: | Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com> |
---|---|
To: | Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: partial unique constraint |
Date: | 2004-04-06 15:18:03 |
Message-ID: | Pine.LNX.4.44.0404061752300.4620-100000@matrix.gatewaynet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
O kyrios Robert Treat egrapse stis Apr 6, 2004 :
> Trying to come up with the proper syntax to meet the following criteria:
>
> create table foo (bar integer, baz boolean UNIQUE (bar, baz = true));
You could simply leave your table as is.
A null vale on baz (equivalent of 'false') will have no impact on the
constraint.
A 't' value (equivalent to 'true') will enforce the constraint.
In other words you can convert your problem as
baz == null <==> baz='false'
baz == 't' <==> baz='true'
(you must never use baz='f')
>
> note the above syntax is not correct, but should demonstrate what i'm
> trying to do; I want to add a unique constraint such that we only allow
> one case of bar and baz = true... i can have unlimited bar and baz =
> false, and there can be multiple bar and baz = true if the bars are
> different... did some doc reading and mail list searching but a valid
> syntax for this seems to be escaping me...
>
> btw I'm pretty sure I could do this with an external trigger, but am
> wondering about a constraint oriented approach
>
> Robert Treat
>
--
-Achilleus
From | Date | Subject | |
---|---|---|---|
Next Message | Paul Thomas | 2004-04-06 15:26:02 | Re: partial unique constraint |
Previous Message | Rod Taylor | 2004-04-06 15:17:49 | Re: partial unique constraint |