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