View Single Post

   
  #3 (permalink)  
Old 04-16-2008, 01:00 AM
Craig Ringer
 
Posts: n/a
Default Re: Issue with NULL varchars

antony baxter wrote:

> // Retrieve that Locale's ID by its Data:
> p = c.prepareStatement("SELECT COUNT(*) FROM testing WHERE variant = ?");


To avoid conditionally rewriting your query to use IS NULL / IS NOT NULL
instead of equality, you could also use IS DISTINCT FROM. Instead of:

where variant = ?

try using:

where not (variant is distinct from ?)


craig=# \pset null '<null>'
Null display is "<null>".

craig=# select null = null;
?column?
----------
<null>
(1 row)

craig=# select not( null is distinct from null );
?column?
----------
t
(1 row)

craig=# select not (1 is distinct from 1);
?column?
----------
t
(1 row)

craig=# select not (1 is distinct from 2);
?column?
----------
f
(1 row)

craig=# select not (null is distinct from 2);
?column?
----------
f
(1 row)


See:

http://www.postgresql.org/docs/8.3/s...omparison.html

--
Craig Ringer

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Reply With Quote