Re: CHECK col A not NULL if col B='x'

Поиск
Список
Период
Сортировка
От Martin Marques
Тема Re: CHECK col A not NULL if col B='x'
Дата
Msg-id 200409281112.02986.martin@bugs.unl.edu.ar
обсуждение исходный текст
Ответ на CHECK col A not NULL if col B='x'  (T E Schmitz <mailreg@numerixtechnology.de>)
Ответы Re: CHECK col A not NULL if col B='x'
Re: CHECK col A not NULL if col B='x'
Список pgsql-sql
El Mar 28 Sep 2004 11:02, T E Schmitz escribió:
> Hello,
>
> Is it possible to set up a table CHECK, which ensures that column A is
> NOT NULL if column B = 'x' ?

CONSTRAINT constraint_name ] CHECK (expression)

CHECK (expression)
The CHECK clause specifies an expression producing a Boolean result which new
or updated rows must satisfy for an insert or update operation to succeed. A
check constraint specified as a column constraint should reference that
column's value only, while an expression appearing in a table constraint may
reference multiple columns.

So I would say that it should be:

CONSTRAINT somename CHECK (B <> 'x' OR A IS NOT NULL)

(use a logical table to build the correct logical expression)

-- 11:05:01 up 16 days,  1:23,  4 users,  load average: 1.26, 0.70, 1.04
-----------------------------------------------------------------
Martín Marqués        | select 'mmarques' || '@' || 'unl.edu.ar'
Centro de Telematica  |  DBA, Programador, Administrador            Universidad Nacional                 del Litoral
-----------------------------------------------------------------


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: FOREIGN KEY and AccessExclusiveLock
Следующее
От: "Alexander M. Pravking"
Дата:
Сообщение: Re: CHECK col A not NULL if col B='x'