Обсуждение: CHECK clause doesn't work with CASE clause

Поиск
Список
Период
Сортировка

CHECK clause doesn't work with CASE clause

От
"Jörg Holetschek"
Дата:
Hi folks,

I have a problem with a CHECK clause that doesn't seem to work properly. The
CREATE TABLE statement looks like this:

CREATE TABLE epilepsy_information (   [...]      epilepsy_class       Char             CHECK (epilepsy_class IN ('f',
'g','n')),      focus                Integer                     REFERENCES focus(id)             CHECK (
 CASE                    WHEN ((focus <> NULL) AND (epilepsy_class = 'f')) THEN
 
TRUE                    WHEN ((focus <> NULL) AND (epilepsy_class IN ('g',
'n'))) THEN FALSE                 END),   [...]
);

It shouldn't be possible to insert a value into focus when epilepsy_class
has one of the values 'g' or 'n'. But it is. Can anyone help?


Thanx sincerefully,
Joerg






Re: CHECK clause doesn't work with CASE clause

От
Tom Lane
Дата:
"J�rg Holetschek" <mail2holly@gmx.de> writes:
>                   CASE
>                      WHEN ((focus <> NULL) AND (epilepsy_class = 'f')) THEN
> TRUE

Try "focus IS NOT NULL".
        regards, tom lane




Re: CHECK clause doesn't work with CASE clause

От
Richard Poole
Дата:
On Thu, Jun 27, 2002 at 11:52:54AM +0200, J?rg Holetschek wrote:
> Hi folks,
> 
> I have a problem with a CHECK clause that doesn't seem to work properly. The

>                   CASE
>                      WHEN ((focus <> NULL) AND (epilepsy_class = 'f')) THEN
> TRUE
>                      WHEN ((focus <> NULL) AND (epilepsy_class IN ('g',
> 'n'))) THEN FALSE
>                   END),

The condition "focus <> NULL" can't ever come out true. You probably
mean IS NOT NULL.

Richard




Re: CHECK clause doesn't work with CASE clause

От
Richard Huxton
Дата:
On Thursday 27 Jun 2002 10:52 am, Jörg Holetschek wrote:
> Hi folks,
>
> I have a problem with a CHECK clause that doesn't seem to work properly.

>                      WHEN ((focus <> NULL) AND (epilepsy_class = 'f')) THEN
>                      WHEN ((focus <> NULL) AND (epilepsy_class IN ('g',

> It shouldn't be possible to insert a value into focus when epilepsy_class
> has one of the values 'g' or 'n'. But it is. Can anyone help?

Should that not be "IS NOT NULL"?

- Richard Huxton