Re: Check constraint

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: Check constraint
Дата
Msg-id 20040317174934.GA15400@wolff.to
обсуждение исходный текст
Ответ на Check constraint  (Francisco Reyes <lists@natserv.com>)
Список pgsql-general
On Wed, Mar 17, 2004 at 12:03:04 +0000,
  Francisco Reyes <lists@natserv.com> wrote:
> I have a "comment" field in a table that I want populated if another field
> has a certain value. Is it possible to set a check constraint for this?
>
> Example:
> Let's say we have fields
> Purchase_type smallint check(purchase_type <4)
> comment       varchar
>
> I need a check rule to something like (pseudo code)
> check (if purchase_type = 3 then NOT NULL comment)

As long as the fields are in the same table you can do this. But you have
to use the IS NOT NULL function rather than try to activate a NOT NULL
constraint. The check would look something like:
check (purchase_type <> 3 OR IS NOT NULL comment)

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

Предыдущее
От: Gregory Wood
Дата:
Сообщение: Re: Check constraint
Следующее
От: "Valter"
Дата:
Сообщение: Relation "xxxxx" does not exist