Re: binding a variable to NULL in perl-DBD - Mailing list pgsql-interfaces

From Daniel Verite
Subject Re: binding a variable to NULL in perl-DBD
Date
Msg-id ceef0d9a-f613-4196-bc9c-b5e90ebcd35e@mm
Whole thread Raw
In response to binding a variable to NULL in perl-DBD  (Max Pyziur <pyz@brama.com>)
Responses Re: binding a variable to NULL in perl-DBD
List pgsql-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



pgsql-interfaces by date:

Previous
From: Max Pyziur
Date:
Subject: binding a variable to NULL in perl-DBD
Next
From: Max Pyziur
Date:
Subject: Re: binding a variable to NULL in perl-DBD