From: | Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Thangavel, Parameswaran" <Parameswaran(dot)Thangavel(at)rsa(dot)com> |
Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Andreas Joseph Krogh <andreas(at)visena(dot)com>, "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Re: PostgresSQL 10 | Driver 42.2.5 | Float Conversion Issue |
Date: | 2020-10-20 21:59:53 |
Message-ID: | CAB=Je-Fs8ZXMiubr1ByNb=EMcJOmreAyKXRS-SnErnqe6Jo6rQ@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
TL;DR: pgjdbc 9.2-1001+ sends floats as binary by default which causes the
conversion issue at the database side.
The workaround is to add binaryTransferDisable=700,701 driver connection
property (the ids are for FLOAT4 and FLOAT4_ARRAY)
OP upgraded from 9.1-901 to 42.2.5 which explains the difference.
---
Vladimir> initial packet, then it upgrades to extra_float_digist=3 in case
server
Vladimir> version is 9.0+
Tom>Hmm, but it's done that for a long while, no?'
It was released in pgjdbc 9.1-901 on 2011-04-18:
https://github.com/pgjdbc/pgjdbc/commit/bcdd8065e4d547a990266ad9d4d90318e90d5a14
And it happens to be exactly the version mentioned in the first mail.
It looks like the interesting change is as follows.
9.1-901 always used bindLiteral(parameterIndex, Float.toString(x),
Oid.FLOAT8); if client uses setFloat(...) (which is exactly the call in the
initial mail).
In other words, it sent the value as a string, and Java converts 1234567f
as 1234567, so the value survived.
Don't ask me why the driver used FLOAT8 for sending float4 data :) I bet it
was made to workaround precision loss issues like we see now.
Dave made the change in 2005
https://github.com/pgjdbc/pgjdbc/commit/ccc8f4c37f9ff1807b0a2efb0fb58e8154311a96
9.2-1001 was released on 2012-10-31 and it introduced binary bind for
certain primitives (see
https://github.com/pgjdbc/pgjdbc/commit/270def76a49500aacb72815bc40892b97af1b6d6
),
so the driver sends float4 as binary, and the database can't convert it to
numeric anymore.
Vladimir
From | Date | Subject | |
---|---|---|---|
Next Message | Vladimir Sitnikov | 2020-10-20 22:10:33 | Re: PostgresSQL 10 | Driver 42.2.5 | Float Conversion Issue |
Previous Message | Tom Lane | 2020-10-20 20:33:06 | Re: PostgresSQL 10 | Driver 42.2.5 | Float Conversion Issue |