i have postgresql function, accepts json, performs processing, , returns json. strange happening when calling stored procedure java appication - float->string convertion incorrect.
processing filtering of data , returning restructured , reorganized result. simplicity let's assume input map [name->float]
, output [float]
.
the problem during intermediate data storage of values native postgresql data type float values lose precision/accuracy/formatting.
here code reproduce
create or replace function do_dummy() returns void language plpgsql $$ declare v_float float[]; v_json jsonb; v_str varchar; begin v_float[0] = 4.1; raise notice 'v_float = %', v_float[0]; raise notice 'jsonb float -> %', ('{"v": 4.1}'::jsonb)->'v'; raise notice 'jsonb float ->> %', ('{"v": 4.1}'::jsonb)->>'v'; v_float[0] = ('{"v": 4.1}'::jsonb)->>'v'; raise notice 'jsonb float ->>::float %', v_float[0]; v_json = array_to_json(v_float); raise notice 'jsonb: %', v_json; v_str = concat('jsonb string: ', v_json::varchar); raise notice '%', v_str; end $$
when executing
select do_dummy();
... via pgadmin, output following , expected:
notice: v_float = 4.1 notice: jsonb float -> 4.1 notice: jsonb float ->> 4.1 notice: jsonb float ->>::float 4.1 notice: jsonb: [4.1] notice: jsonb string: [4.1]
when executing same java application, result following
notice: v_float = 4.0999999999999996 notice: jsonb float -> 4.1 notice: jsonb float ->> 4.1 notice: jsonb float ->>::float 4.0999999999999996 notice: jsonb: [4.0999999999999996] notice: jsonb string: [4.0999999999999996]
since no data transferred to/from server in function call - problem occurs server-side, in jdbc driver triggering problem.
what can wrong jdbc connection in regard?
i'm using jdbc driver v9.4.1207 (the latest 1 @ moment).
the driver initializes extra_float_digits
.
if run
set extra_float_digits = 0;
before calling function, same output via jdbc
Comments
Post a Comment