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

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

From: "Marc Mamin" <M(dot)Mamin(at)intershop(dot)de>
To: "Andreas Kretschmer" <akretschmer(at)spamfence(dot)net>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Prevent double entries ... no simple unique index
Date: 2012-07-11 10:53:52
Message-ID: C4DAC901169B624F933534A26ED7DF310861B61A@JENMAIL01.ad.intershop.net (view raw or flat)
Thread:
Lists: pgsql-sql
> 
> 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);

best regards,

Marc Mamin



In response to

Responses

pgsql-sql by date

Next:From: Andreas KretschmerDate: 2012-07-12 05:14:45
Subject: Re: Prevent double entries ... no simple unique index
Previous:From: Rosser SchwarzDate: 2012-07-11 09:11:06
Subject: Re: Prevent double entries ... no simple unique index

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