Re: UNIQUE columnt depdening on other column???

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: UNIQUE columnt depdening on other column???
Дата
Msg-id 40BDC661.6070305@archonet.com
обсуждение исходный текст
Ответ на UNIQUE columnt depdening on other column???  ("Andrei Bintintan" <klodoma@ar-sd.net>)
Список 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


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Andrei Bintintan"
Дата:
Сообщение: UNIQUE columnt depdening on other column???
Следующее
От: Reinoud van Leeuwen
Дата:
Сообщение: Re: UNIQUE columnt depdening on other column???