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

Re: Prevent double entries ... no simple unique index

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Prevent double entries ... no simple unique index
Date: 2012-07-12 05:14:45
Message-ID: 20120712051445.GA5421@tux (view raw or flat)
Thread:
Lists: pgsql-sql
Marc Mamin <M(dot)Mamin(at)intershop(dot)de> wrote:

> > 
> > Or this one:
> > 
> > test=*# create unique index on log((case when state = 0 then 0 when
> > state = 1 then 1 else null end));
> > CREATE INDEX
> > 
> > 
> > Now you can insert one '0' and one '1' - value - but no more.
> 
> Hi,
> 
> A partial index would do the same, but requires less space: 
> 
> create unique index on log(state) WHERE state IN (0,1);

Right! ;-)


Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

In response to

Responses

pgsql-sql by date

Next:From: AndreasDate: 2012-07-12 08:44:32
Subject: Re: Prevent double entries ... no simple unique index
Previous:From: Marc MaminDate: 2012-07-11 10:53:52
Subject: Re: Prevent double entries ... no simple unique index

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