Re: Prevent double entries ... no simple unique index - Mailing list pgsql-sql

From Marc Mamin
Subject Re: Prevent double entries ... no simple unique index
Date
Msg-id C4DAC901169B624F933534A26ED7DF310861B61A@JENMAIL01.ad.intershop.net
Whole thread Raw
In response to Re: Prevent double entries ... no simple unique index  (Andreas Kretschmer <akretschmer@spamfence.net>)
Responses Re: Prevent double entries ... no simple unique index
List 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




pgsql-sql by date:

Previous
From: Rosser Schwarz
Date:
Subject: Re: Prevent double entries ... no simple unique index
Next
From: Andreas Kretschmer
Date:
Subject: Re: Prevent double entries ... no simple unique index