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


-- 
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)  latest in thread

Message-ID: <ceef0d9a-f613-4196-bc9c-b5e90ebcd35e@mm>
Permalink:  ../ceef0d9a-f613-4196-bc9c-b5e90ebcd35e@mm/
Also on:    postgresql.org/message-id/ceef0d9a-f613-4196-bc9c-b5e90ebcd35e@mm

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: daniel@manitou-mail.org, pyz@brama.com
  Subject: Re: binding a variable to NULL in perl-DBD
  In-Reply-To: <ceef0d9a-f613-4196-bc9c-b5e90ebcd35e@mm>

* 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