From: | Max Pyziur <pyz(at)brama(dot)com> |
---|---|
To: | Daniel Verite <daniel(at)manitou-mail(dot)org> |
Cc: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | Re: binding a variable to NULL in perl-DBD |
Date: | 2013-08-24 21:52:44 |
Message-ID: | alpine.LRH.2.03.1308241748220.7462@brama.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)brama(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Vesa-Matti J Kari | 2013-09-02 08:06:47 | Strange hanging bug in a simple milter |
Previous Message | Daniel Verite | 2013-08-22 20:48:55 | Re: binding a variable to NULL in perl-DBD |