Re: Problem with select and null

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Problem with select and null
Дата
Msg-id 7717.1093882636@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Problem with select and null  ("Frank Millman" <frank@chagford.com>)
Список pgsql-general
"Frank Millman" <frank@chagford.com> writes:
> 'SELECT (null * null)' returns null

IMHO you really ought to get an error from that.  It's just as type-free
as

    select ('FOO' * 'bar');

which currently gives a rather silly result.  The reason this happens
is that the type "char" (not to be confused with char) has arithmetic
operators, and we have an implicit cast from text to "char" so these
operators are able to suck in constructs that are probably user errors.
I have previously proposed removing these operators, which seem quite
useless anyway, but didn't get around to doing it for 8.0.

> Under some circumstances my program generates the above select statement, s=
> o this is not an academic question.

Figure out what type your program is expecting the null to be, and
explicitly cast it to that type.  For instance

    SELECT ((null::int * null::int) - 0);

            regards, tom lane

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

Предыдущее
От: "Michael Paesold"
Дата:
Сообщение: Re: Problem with select and null
Следующее
От: Josué Maldonado
Дата:
Сообщение: Generic/Common trigger