Check/unique constraint question

Поиск
Список
Период
Сортировка
От Jeff Frost
Тема Check/unique constraint question
Дата
Msg-id Pine.LNX.4.64.0603050015050.29717@discord.dyndns.org
обсуждение исходный текст
Ответы Re: Check/unique constraint question  ("Nikolay Samokhvalov" <samokhvalov@gmail.com>)
Re: Check/unique constraint question  (Michael Glaesemann <grzm@myrealbox.com>)
Список pgsql-sql
I have a table with the following structure:
   Column   |  Type   |       Modifiers
------------+---------+----------------------- active     | boolean | not null default true id         | integer | not
null
(other columns left out)

And would like to make a unique constraint which would only check the 
uniqueness of id if active=true.

So, the following values would be acceptable:

('f',5)
('f',5)
('t',5)

But these would not be:

('t',5)
('t',5)

Basically, I want something like:
ALTER TABLE bar ADD CONSTRAINT foo UNIQUE(active (where active='t'),id)

But the above does not appear to exist.  Is there a simple way to create a 
check constraint for this type of situation, or do I need to create a function 
to eval a check constraint?

-- 
Jeff Frost, Owner     <jeff@frostconsultingllc.com>
Frost Consulting, LLC     http://www.frostconsultingllc.com/
Phone: 650-780-7908    FAX: 650-649-1954


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

Предыдущее
От: "Peter Ivarsson"
Дата:
Сообщение: unsubscribe
Следующее
От: "Nikolay Samokhvalov"
Дата:
Сообщение: Re: Check/unique constraint question