Re: binding a variable to NULL in perl-DBD

"Daniel Verite" <[email protected]> Thu, 22 Aug 2013 22:48:55 +0200
Newsgroups gmane.comp.db.postgresql.interfaces
Message-ID <ceef0d9a-f613-4196-bc9c-b5e90ebcd35e@mm>
	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 ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces