Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VCboc-00028w-LL for pgsql-interfaces@arkaria.postgresql.org; Thu, 22 Aug 2013 20:49:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VCbob-0003lb-Ll for pgsql-interfaces@arkaria.postgresql.org; Thu, 22 Aug 2013 20:49:09 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VCboa-0003lT-KX for pgsql-interfaces@postgresql.org; Thu, 22 Aug 2013 20:49:08 +0000 Received: from sd-21892.dedibox.fr ([88.191.123.145]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VCboT-0003Pe-JT for pgsql-interfaces@postgresql.org; Thu, 22 Aug 2013 20:49:08 +0000 Received: by sd-21892.dedibox.fr (Postfix, from userid 1001) id ECA6A4461E2; Thu, 22 Aug 2013 22:48:59 +0200 (CEST) Content-Type: text/plain; charset="iso-8859-15" Content-Disposition: inline Content-Transfer-Encoding: 7bit MIME-Version: 1.0 Subject: Re: binding a variable to NULL in perl-DBD From: "Daniel Verite" To: "Max Pyziur" CC: pgsql-interfaces@postgresql.org In-Reply-To: Date: Thu, 22 Aug 2013 22:48:55 +0200 Message-ID: X-Mailer: Manitou v1.3.1 X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-interfaces Precedence: bulk Sender: pgsql-interfaces-owner@postgresql.org 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