Re: partial unique constraint - Mailing list pgsql-sql

From Paul Thomas
Subject Re: partial unique constraint
Date
Msg-id 20040406162602.F6112@bacon
Whole thread Raw
In response to partial unique constraint  (Robert Treat <xzilla@users.sourceforge.net>)
List pgsql-sql
On 06/04/2004 15:29 Robert Treat wrote:
> Trying to come up with the proper syntax to meet the following criteria:
> 
> create table foo (bar integer, baz boolean UNIQUE (bar, baz = true));
> 
> 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

What about

create table foo (bar integer, baz boolean);

create unique index foo_bar_baz on foo(bar, baz) where baz = true;

-- 
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for 
Business             |
| Computer Consultants         | 
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+


pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: partial unique constraint
Next
From: Rod Taylor
Date:
Subject: Re: partial unique constraint