Re: Differentiate Between Zero-Length String and NULL Column Values

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Phillip Smith <phillip(dot)smith(at)weatherbeeta(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Differentiate Between Zero-Length String and NULL Column Values
Date: 2007-01-30 05:45:43
Message-ID: 20070130054543.GA98994@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Jan 30, 2007 at 04:32:22PM +1100, Phillip Smith wrote:
> The second row (401600) is what I'm interested in for this particular
> problem. The problem is when I try and add a WHERE clause:
> SELECT * FROM tmpstk WHERE ean = '';
> SELECT * FROM tmpstk WHERE TRIM(ean) = '';
> SELECT * FROM tmpstk WHERE ean = NULL;
> None of the above queries return any rows.

Checking for equality against NULL won't work unless you have
transform_null_equals set, which you shouldn't. Use IS NULL instead:

SELECT * FROM tmpstk WHERE ean IS NULL;

--
Michael Fuhr

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Niklas Bergius 2007-01-30 10:40:39 Arrays, multidimensional ANY (v 8.2)
Previous Message Phillip Smith 2007-01-30 05:32:22 Differentiate Between Zero-Length String and NULL Column Values