Re: UNIQUE columnt depdening on other column???

From: Richard Huxton <dev(at)archonet(dot)com>
To: Andrei Bintintan <klodoma(at)ar-sd(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: UNIQUE columnt depdening on other column???
Date: 2004-06-02 12:21:53
Message-ID: 40BDC661.6070305@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Andrei Bintintan wrote:
> Hi,
>
> I have a problem.
>
> Let's say I have the following table:
> CREATE TABLE rekl_element(
> id serial PRIMARY KEY,
> active boolean NOT NULL DEFAULT 'y',
> num int4 NOT NULL,
> text varchar(10)
> );
>
> Now I want that "num" column is "unique" but only for those columns that
> have active='y'. For the columns that have active='f' I don't care if num is
> unique or not. I'm asking this because num will be doubled some times.

Non-standard but elegant:
CREATE UNIQUE INDEX my_partially_unique_index ON rekl_element (num)
WHERE active;

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Reinoud van Leeuwen 2004-06-02 12:43:45 Re: UNIQUE columnt depdening on other column???
Previous Message Andrei Bintintan 2004-06-02 11:39:45 UNIQUE columnt depdening on other column???