Re: Unique cosntraint based on contents of a field?

From: Jaime Casanova <jcasanov(at)systemguards(dot)com(dot)ec>
To: Warren Bell <warrenbell2(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Unique cosntraint based on contents of a field?
Date: 2010-04-08 03:48:36
Message-ID: r2g3073cc9b1004072048r159cf35hfe03576b8da8a627@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Apr 7, 2010 at 10:30 PM, Warren Bell <warrenbell2(at)gmail(dot)com> wrote:
> Is there a way to create a unique constraint based on the content of a
> field? For instance, say you have an integer field where you only want one
> record with the number 1 in that field but there can be many records with
> say the number 2 or any other single number in that field.
>

create unique index unique_field_idx
on table1(field)
where field = 1;

--
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Asesoría y desarrollo de sistemas
Guayaquil - Ecuador
Cel. +59387171157

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Smith 2010-04-08 05:56:24 Re: Solid State Drives with PG
Previous Message Warren Bell 2010-04-08 02:30:12 Unique cosntraint based on contents of a field?