agora inbox for pgsql-interfaces@postgresql.org  
help / color / mirror / Atom feed
From: Max Pyziur <pyz@brama.com>
To: Daniel Verite <daniel@manitou-mail.org>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: binding a variable to NULL in perl-DBD
Date: Sat, 24 Aug 2013 17:52:44 -0400 (EDT)
Message-ID: <alpine.LRH.2.03.1308241748220.7462@brama.com> (raw)
In-Reply-To: <ceef0d9a-f613-4196-bc9c-b5e90ebcd35e@mm>
References: <ceef0d9a-f613-4196-bc9c-b5e90ebcd35e@mm>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces



view thread (3+ messages)

Message-ID: <alpine.LRH.2.03.1308241748220.7462@brama.com>
Permalink:  ../alpine.LRH.2.03.1308241748220.7462@brama.com/
Also on:    postgresql.org/message-id/alpine.LRH.2.03.1308241748220.7462@brama.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: pyz@brama.com, daniel@manitou-mail.org
  Subject: Re: binding a variable to NULL in perl-DBD
  In-Reply-To: <alpine.LRH.2.03.1308241748220.7462@brama.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox