Re: Help with exclusion constraint

Поиск
Список
Период
Сортировка
От hari.fuchs@gmail.com
Тема Re: Help with exclusion constraint
Дата
Msg-id 87ppl6e0gz.fsf@hf.protecting.net
обсуждение исходный текст
Ответ на Help with exclusion constraint  (Moshe Jacobson <moshe@neadwerx.com>)
Ответы Re: Help with exclusion constraint  (Moshe Jacobson <moshe@neadwerx.com>)
Список pgsql-general
Moshe Jacobson <moshe@neadwerx.com> writes:

> Take the following table:
>
> CREATE TABLE exclusion_example AS
> (
>      pk_col  integer primary key,
>      fk_col integer not null references other_table,
>      bool_col boolean not null
> );
>
> I want to ensure that for any given value of fk_col that there is a maximum
> of one row with bool_col = true.

This should be what you want:

ALTER TABLE exclusion_example
ADD CONSTRAINT ex
EXCLUDE (fk_col WITH =) WHERE (bool_col);

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

Предыдущее
От: Igor Neyman
Дата:
Сообщение: Re: Help with exclusion constraint
Следующее
От: Moshe Jacobson
Дата:
Сообщение: Re: Help with exclusion constraint