Re: float8 transmitted in ascii
От | Dave Cramer |
---|---|
Тема | Re: float8 transmitted in ascii |
Дата | |
Msg-id | CADK3HHJFnXUiU+gWAfGvVCe2Xu6sN_QNZdxjKaFAVGGzoxMWXQ@mail.gmail.com обсуждение исходный текст |
Ответ на | float8 transmitted in ascii (Timo Nentwig <postgres@nentwig.biz>) |
Ответы |
Re: float8 transmitted in ascii
|
Список | pgsql-jdbc |
If I understand you correctly in java you did:
select 47.88::DOUBLE PRECISION,
(47.88::DOUBLE PRECISION)::text,
(47.88::DOUBLE PRECISION)::numeric,
replace((47.88::DOUBLE PRECISION)::text, '.', ',');
(47.88::DOUBLE PRECISION)::text,
(47.88::DOUBLE PRECISION)::numeric,
replace((47.88::DOUBLE PRECISION)::text, '.', ',');
and the two numeric values are correct, but the text values are wrong ?
Which column is:
52,55,46,56,56,48,48,48,48,48,48,48,48,48,48,48,48,50,54
?
On 29 April 2015 at 11:40, Timo Nentwig <postgres@nentwig.biz> wrote:
Hi!
9.1-901-1.jdbc4 (and probably also the latest 9.4 driver, did most testing with the 9.1 one, though [on pg 9.4.1])
postgres=# select 47.88::DOUBLE PRECISION,
(47.88::DOUBLE PRECISION)::text,
(47.88::DOUBLE PRECISION)::numeric,
replace((47.88::DOUBLE PRECISION)::text, '.', ',');
float8 | text | numeric | replace
--------+-------+---------+---------
47.88 | 47.88 | 47.88 | 47,88
Good. What I actually get with JDBC doesn't look quite as good, though:
47.88
47.8800000000000026
47.88
47,8800000000000026
So, I looked into the driver and the first surprise was that for the first 2 columns the driver gets an identical 19-byte array; despite one is a float8 (and 8!=19) and the other is supposedly Ba string (with 5 characters).
Here it is (AbstractJdbcResultSet.this_row):
52,55,46,56,56,48,48,48,48,48,48,48,48,48,48,48,48,50,54
Well, that appears to be the 19-char *string* '47.8800000000000026' in ascii.
And indeed:
return toDouble( getFixedString(columnIndex) );
return Double.parseDouble(s);
Srsly?! Doubles are sent over the wire in "some" text representation and then parsed in the JDBC driver? Really?
What I still don't get, though: if this is what postgres sends over the wire, why does psql/pgadmin print the 4th (and 2nd) column correctly?
thx
tcn
P.S.:
if ("hstore".equals(getPGType(columnIndex))) {
return HStoreConverter.toString((Map) obj);
}
So, internally we already have a java.util.Map and there are a few 'solutions' out there that *parse* the string representation back into java.util.Map? Srsly?
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
В списке pgsql-jdbc по дате отправления: