tricky CHECK condition

Поиск
Список
Период
Сортировка
От Arcady Genkin
Тема tricky CHECK condition
Дата
Msg-id 87zophgaeh.fsf@tea.thpoon.com
обсуждение исходный текст
Ответы Re: tricky CHECK condition  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: tricky CHECK condition  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
How could I specify a condition in 'CHECK' constraint for a column to
check that its value must only appear once in *some* rows of a table?
Sort of a local "UNIQUE"... For example, in CDs world:

create table tracks (
       -- Unique track identifier
       id serial primary key,
       -- Which disk the track is from
       disk_id int4 references disks (id),
       -- Track number in a disk
       track_number int2,
       check (WHAT I WANT GOES HERE) );

I want to check values of `track_number' to be unique for the
disk. Basically, I want to check that an SQL query

select track_number from tracks T
       where T.disk_id=disk_id and T.track_number=track_number;

is empty... Is it possible to run an SQL query in a condition clause?
I looked thru documentation, but couldn't find anything relevant.
--
Arcady Genkin                                 http://www.thpoon.com
Nostalgia isn't what it used to be.

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

Предыдущее
От: Palle Girgensohn
Дата:
Сообщение: Re: [PORTS] Logging (was Re: PostgreSQL 7.0-2 RPMset released.)
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: tricky CHECK condition