Re: Issue with NULL varchars

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: antony baxter <antony(dot)baxter(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Issue with NULL varchars
Date: 2008-03-25 10:25:59
Message-ID: 47E8D337.2030807@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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/static/functions-comparison.html

--
Craig Ringer

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Albe Laurenz 2008-03-25 14:46:10 Re: Issue with NULL varchars
Previous Message Craig Ringer 2008-03-25 10:00:40 Re: Issue with NULL varchars