From: Tazhkenov Denis <imaskar@live.ru>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: JDBC driver setNull(_,Types.OTHER) bug
Date: Wed, 16 Sep 2015 13:54:50 +0300
Message-ID: <DUB128-W530EEFFF5B2450BD29CD9EAB5B0@phx.gbl> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
tl/dr:
select 'ok' where ?=? or (? is null)
stp.setObject(1, UUID.randomUUID(), Types.OTHER);
stp.setNull(2, Types.OTHER); // works
stp.setNull(3, Types.OTHER); // doesn't work
tl/dr end
Suppose, you use uuid columns in your table and need to compare a cloumn value with a parameter and alose to compare this parameter with null. In this case you have to use Types.OTHER to compare parameter with your column, but you can't use Types.OTHER whith (? is null) clause, because it issues error "can't detect parameter datatype for parameter$_" (not actual message, mine is localized).
Tested with versions:
driver
postgresql-9.4-1202.jdbc42
postgresql-9.4-1202.jdbc41
postgresql-9.3-1101.jdbc4db
postgres (PostgreSQL) 9.3.5
Test case:
http://ideone.com/W3sfhI
It does have some workarounds:
*if you know that parameter will be of uuid type, add cast to your clause;
-inconvinient, if your statements are auto-generated or if you can't change them (responsibility scope!);
-may slow down queries if used too broad;
*if at runtime you are setting uuid parameter to null, use Types.VARCHAR;
-didn't test, if it would correctly work when comparing with actual column, or writing there.
Maybe there is some pg-specific typeId for the uuid type?
Regards,
Denis Tazhkenov
=
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: imaskar@live.ru
Subject: Re: JDBC driver setNull(_,Types.OTHER) bug
In-Reply-To: <DUB128-W530EEFFF5B2450BD29CD9EAB5B0@phx.gbl>
References: <DUB128-W530EEFFF5B2450BD29CD9EAB5B0@phx.gbl>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox