Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZcAMg-0006sY-Si for pgsql-bugs@arkaria.postgresql.org; Wed, 16 Sep 2015 10:55:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZcAMf-00051n-SX for pgsql-bugs@arkaria.postgresql.org; Wed, 16 Sep 2015 10:55:01 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZcAMe-00051H-Rj for pgsql-bugs@postgresql.org; Wed, 16 Sep 2015 10:55:01 +0000 Received: from dub004-omc1s25.hotmail.com ([157.55.0.224]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZcAMX-0003T6-5k for pgsql-bugs@postgresql.org; Wed, 16 Sep 2015 10:54:59 +0000 Received: from DUB128-W53 ([157.55.0.238]) by DUB004-OMC1S25.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Wed, 16 Sep 2015 03:54:50 -0700 X-TMN: [HHE9/j9SUWE2AX3iC+YEOFb7JGPiK9Rg] X-Originating-Email: [imaskar@live.ru] Message-ID: Content-Type: multipart/alternative; boundary="_276c1c24-cd63-4d7e-bcd4-c049b5bf59f5_" From: Tazhkenov Denis To: "pgsql-bugs@postgresql.org" Subject: JDBC driver setNull(_,Types.OTHER) bug Date: Wed, 16 Sep 2015 13:54:50 +0300 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 16 Sep 2015 10:54:50.0619 (UTC) FILETIME=[1C55ACB0:01D0F06E] X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --_276c1c24-cd63-4d7e-bcd4-c049b5bf59f5_ Content-Type: text/plain; charset="iso-8859-5" Content-Transfer-Encoding: quoted-printable tl/dr: select 'ok' where ?=3D? or (? is null) stp.setObject(1=2C UUID.randomUUID()=2C Types.OTHER)=3B stp.setNull(2=2C Types.OTHER)=3B // works stp.setNull(3=2C Types.OTHER)=3B // doesn't work tl/dr end Suppose=2C 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 th= is case you have to use Types.OTHER to compare parameter with your column= =2C but you can't use Types.OTHER whith (? is null) clause=2C because it is= sues error "can't detect parameter datatype for parameter$_" (not actual me= ssage=2C mine is localized). Tested with versions: =0A= =0A= driver postgresql-9.4-1202.jdbc42=0A= =0A= postgresql-9.4-1202.jdbc41=0A= =0A= 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=2C add cast to your clause= =3B -inconvinient=2C if your statements are auto-generated or if you can't cha= nge them (responsibility scope!)=3B -may slow down queries if used too broad=3B *if at runtime you are setting uuid parameter to null=2C use Types.VARCHAR= =3B -didn't test=2C if it would correctly work when comparing with actual colu= mn=2C or writing there. Maybe there is some pg-specific typeId for the uuid type? Regards=2C Denis Tazhkenov = --_276c1c24-cd63-4d7e-bcd4-c049b5bf59f5_ Content-Type: text/html; charset="iso-8859-5" Content-Transfer-Encoding: quoted-printable
tl/dr:
select 'ok' where ?=3D= ? or (? is null)
stp.setObject(1=2C UUID.randomUUID()=2C Types.OTHER)=3B=
stp.setNull(2=2C Types.OTHER)=3B // works
stp.setNull(3=2C Types.OTH= ER)=3B // doesn't work
tl/dr end

Suppose=2C 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.OT= HER to compare parameter with your column=2C but you can't use Types.OTHER = whith (? is null) clause=2C because it issues error "can't detect parameter= datatype for parameter$_" (not actual message=2C mine is localized).
Tested with versions:
=0A= =0A=

driver

postgresql-9.4-120= 2.jdbc42

=0A= =0A=

postgresql-9.4-= 1202.jdbc41

=0A= =0A=

postgresql-9.3-= 1101.jdbc4

db
 =3B postgres (PostgreSQL) 9.3.5

Test case:<= br>http://ideone.com/W3sfhI

It does have some workarounds:
*if yo= u know that parameter will be of uuid type=2C add cast to your clause=3B =3B-inconvinient=2C if your statements are auto-generated or if you c= an't change them (responsibility scope!)=3B
 =3B-may slow down queri= es if used too broad=3B
*if at runtime you are setting uuid parameter to= null=2C use Types.VARCHAR=3B
 =3B-didn't test=2C if it would correc= tly work when comparing with actual column=2C or writing there.

Mayb= e there is some pg-specific typeId for the uuid type?

Regards=2C
= Denis Tazhkenov
= --_276c1c24-cd63-4d7e-bcd4-c049b5bf59f5_--