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

Поиск
Список
Период
Сортировка
От Alexander M. Pravking
Тема Re: CHECK col A not NULL if col B='x'
Дата
Msg-id 20040928141504.GA17595@dyatel.antar.bryansk.ru
обсуждение исходный текст
Ответ на CHECK col A not NULL if col B='x'  (T E Schmitz <mailreg@numerixtechnology.de>)
Список pgsql-sql
On Tue, Sep 28, 2004 at 03:02:02PM +0100, T E Schmitz wrote:
> Hello,
> 
> Is it possible to set up a table CHECK, which ensures that column A is 
> NOT NULL if column B = 'x' ?

Sure.

fduch@~=# CREATE TABLE test (
fduch@~(# a integer check (case when b = 'x' then a is not null else true end),
fduch@~(# b text);
CREATE TABLE
fduch@~=# INSERT INTO test VALUES (null, '123');
INSERT 107538 1
fduch@~=# INSERT INTO test VALUES (null, 'x');
ERROR:  new row for relation "test" violates check constraint "test_a"
fduch@~=# INSERT INTO test VALUES (1, 'x');
INSERT 107539 1

-- 
Fduch M. Pravking


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

Предыдущее
От: Martin Marques
Дата:
Сообщение: Re: CHECK col A not NULL if col B='x'
Следующее
От: Achilleus Mantzios
Дата:
Сообщение: Re: FOREIGN KEY and AccessExclusiveLock