Re: float8 transmitted in ascii

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Timo Nentwig <postgres(at)nentwig(dot)biz>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: float8 transmitted in ascii
Date: 2015-04-29 22:51:34
Message-ID: CADK3HHJFnXUiU+gWAfGvVCe2Xu6sN_QNZdxjKaFAVGGzoxMWXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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, '.', ',');

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

?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 29 April 2015 at 11:40, Timo Nentwig <postgres(at)nentwig(dot)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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2015-04-29 23:59:52 Re: float8 transmitted in ascii
Previous Message Timo Nentwig 2015-04-29 15:40:44 float8 transmitted in ascii