float8 transmitted in ascii
От | Timo Nentwig |
---|---|
Тема | float8 transmitted in ascii |
Дата | |
Msg-id | alpine.LNX.2.03.1504291738060.41809@nentwig.biz обсуждение исходный текст |
Ответы |
Re: float8 transmitted in ascii
|
Список | pgsql-jdbc |
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?
В списке pgsql-jdbc по дате отправления: