Re: interesting check constraint behavior

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: interesting check constraint behavior
Дата
Msg-id 4117BD37-F9A5-4230-BA3D-83265A4B8EA1@solfertje.student.utwente.nl
обсуждение исходный текст
Ответ на interesting check constraint behavior  ("Gauthier, Dave" <dave.gauthier@intel.com>)
Ответы Re: interesting check constraint behavior  ("Gauthier, Dave" <dave.gauthier@intel.com>)
Список pgsql-general
On 7 Jan 2010, at 24:12, Gauthier, Dave wrote:

> thedb=# create table foo (col1 text, constraint chk check (col1 in ('a','b','c',null)));
> CREATE TABLE
> thedb=# insert into foo (col1) values ('xxx');
> INSERT 0 1
>
> Hmmmm... I would have thought that this would have violated the constraint because ‘xxx’ is not null and nit one of
theallowed values. 

As Tom already explained, "value in ('yada', 'yada', null)" evaluates to null. You'll need to make sure your check
expressionevaluates to either true or false - not null. 

I guess you need: check(col1 in ('a', 'b', 'c') or col1 is null)

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,4b45bc2610731598743439!



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

Предыдущее
От: Konrad Garus
Дата:
Сообщение: Re: Rows missing from table despite FK constraint
Следующее
От: Merlin Moncure
Дата:
Сообщение: Re: How psql source code can be protected?