pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Robert Treat <xzilla@users.sourceforge.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: partial unique constraint
Date: Tue, 6 Apr 2004 08:05:15 -0700 (PDT)
Message-ID: <20040406080241.G36214@megazone.bigpanda.com> (raw)
In-Reply-To: <1081261772.31785.48.camel@camel>
References: <1081261772.31785.48.camel@camel>


On Tue, 6 Apr 2004, 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

You can't precisely with a constraint (AFAIR sql is marginally limited in
that way at least in 92 and 99), but you should be able to do it with a
partial unique index something like
 create unique index foo_i on foo(bar) where baz is true;



view thread (9+ messages)  latest in thread

Message-ID: <20040406080241.G36214@megazone.bigpanda.com>
Permalink:  ../20040406080241.G36214@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20040406080241.G36214@megazone.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone.bigpanda.com, xzilla@users.sourceforge.net
  Subject: Re: partial unique constraint
  In-Reply-To: <20040406080241.G36214@megazone.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox