Re: binding a variable to NULL in perl-DBD

Поиск
Список
Период
Сортировка
От Daniel Verite
Тема Re: binding a variable to NULL in perl-DBD
Дата
Msg-id ceef0d9a-f613-4196-bc9c-b5e90ebcd35e@mm
обсуждение исходный текст
Ответ на binding a variable to NULL in perl-DBD  (Max Pyziur <pyz@brama.com>)
Ответы Re: binding a variable to NULL in perl-DBD  (Max Pyziur <pyz@brama.com>)
Список pgsql-interfaces
    Max Pyziur wrote:

> I'm trying to determine how to pass "NULL" to a variable, specifically in 
> the conditional section of a SQL statement:
> 
> SELECT moo
> FROM foo aa
> WHERE field1 = ?
> AND field2 = ?

Perl's undef is used to pass NULL as a literal but field=NULL
will never be true.

> SELECT moo
> FROM foo aa
> WHERE field1 = 'goo'
> AND field2 IS NULL

You may use:
WHERE field1 = ?
AND field2 IS NOT DISTINCT FROM ?

which conveys the idea that field2 must be equal to the value passed,
and works as expected with both non-NULL literals and NULL (undef).

Best regards,
-- 
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org



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

Предыдущее
От: Max Pyziur
Дата:
Сообщение: binding a variable to NULL in perl-DBD
Следующее
От: Max Pyziur
Дата:
Сообщение: Re: binding a variable to NULL in perl-DBD