Re: binding a variable to NULL in perl-DBD

Поиск
Список
Период
Сортировка
От Max Pyziur
Тема Re: binding a variable to NULL in perl-DBD
Дата
Msg-id alpine.LRH.2.03.1308241748220.7462@brama.com
обсуждение исходный текст
Ответ на Re: binding a variable to NULL in perl-DBD  ("Daniel Verite" <daniel@manitou-mail.org>)
Список pgsql-interfaces
On Thu, 22 Aug 2013, Daniel Verite wrote:

>     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 ?

Much thanks for your help. The way that I'm making this work is that on 
the command line for the argument of interest I use the word NULL, then in 
the perl code I have:
if ($FIELD2_CODE eq "NULL") { undef($FIELD2_CODE); }

and then in the SQL:
"AND field2 IS NOT DISTINCT FROM ?" seems to work

Do I have a correct understanding of Postgres SQL's vernacular and 
application here?

> 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,
>

Thank you again,

Max Pyziur
pyz@brama.com



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

Предыдущее
От: "Daniel Verite"
Дата:
Сообщение: Re: binding a variable to NULL in perl-DBD
Следующее
От: Vesa-Matti J Kari
Дата:
Сообщение: Strange hanging bug in a simple milter