Skip site navigation (1) Skip section navigation (2)

Re: Deleted Flag/Unique Constraint

From: "Bryan Murphy" <bryan(dot)murphy(at)gmail(dot)com>
To: "Jonathan Hedstrom" <jhedstrom(at)desc(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Deleted Flag/Unique Constraint
Date: 2007-03-30 00:26:51
Message-ID: bd8531800703291726t25f80f78x4f16d6c21b4472c@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
Thanks!  That works great!

Bryan

On 3/29/07, Jonathan Hedstrom <jhedstrom(at)desc(dot)org> wrote:
>
> Bryan Murphy wrote:
>
> > Is it possible to declare a unique constraint in combination with a
> > deleted flag?
> >
> > For example, if I have a table like this:
> >
> > CREATE TABLE
> > (
> >   ID NOT NULL PRIMARY KEY,
> >   Key VARCHAR(32) NOT NULL,
> >   Value VARCHAR(32) NOT NULL,
> >   Deleted INT NOT NULL DEFAULT 0
> > );
> >
> > can I declare a unique constraint that only checks Key and Value when
> > Deleted = 0?
>
> Yes, something like this:
>
> CREATE UNIQUE INDEX index_name ON table_name ( unique_field) WHERE
> deleted=0;
>
> -Jonathan
>

In response to

Responses

pgsql-general by date

Next:From: Bryan MurphyDate: 2007-03-30 00:31:10
Subject: Re: Deleted Flag/Unique Constraint
Previous:From: John D. BurgerDate: 2007-03-30 00:06:06
Subject: Re: Deleted Flag/Unique Constraint

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group