pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: Andreas Joseph Krogh <andreas@visena.com>
Cc: Thangavel, Parameswaran <Parameswaran.Thangavel@rsa.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: PostgresSQL 10 | Driver 42.2.5 | Float Conversion Issue
Date: Tue, 20 Oct 2020 18:41:54 -0400
Message-ID: <681507.1603233714@sss.pgh.pa.us> (raw)
In-Reply-To: <CAB=Je-GGS0c8im6suhe=zwvW21TTWyxJ=uXarzq6fLmVm-9eUA@mail.gmail.com>
References: <CH2PR19MB3798B6096BD4EA60C2068367831F0@CH2PR19MB3798.namprd19.prod.outlook.com>
	<VisenaEmail.9.b226ab802321bcdc.17544a6d3e3@tc7-visena>
	<CH2PR19MB3798DAEA77750DD4F4CE67A0831F0@CH2PR19MB3798.namprd19.prod.outlook.com>
	<VisenaEmail.e.3213a432433c7179.17544c1d629@tc7-visena>
	<CAKFQuwbbYTc63HeEBPXcDzPU28Do4z+y9ZEwQKVFwCnbPP1FaQ@mail.gmail.com>
	<VisenaEmail.90.b09bf69bfcec8e52.17546ec4f83@tc7-visena>
	<652597.1603214274@sss.pgh.pa.us>
	<VisenaEmail.91.1593ba84a90d02a5.17547533c82@tc7-visena>
	<CAKFQuwYwsp7-5WUPsgg_ZpbtOOQ9kuvbEsD1LWLboz2qD80uwQ@mail.gmail.com>
	<VisenaEmail.98.ebf0ca280ce8e2b7.175476a101e@tc7-visena>
	<CAKFQuwYa=VsYuhCYEn+jCWc_s52h-oOVRzL696iQSJKHHbELOg@mail.gmail.com>
	<674136.1603223598@sss.pgh.pa.us>
	<CAB=Je-H8NiTt_+roUXzv=UiL6QWG-7QzihMVvpXrwyq8FLuo3w@mail.gmail.com>
	<675895.1603225986@sss.pgh.pa.us>
	<CAB=Je-GGS0c8im6suhe=zwvW21TTWyxJ=uXarzq6fLmVm-9eUA@mail.gmail.com>

Vladimir Sitnikov <sitnikov.vladimir@gmail.com> writes:
> Tom>Note the waffling immediately after that, though.
> I assume PostgreSQL switched to Ryu around release 12 or so.

> Should float4_numeric switch to Ryu as well?
> I guess it would be both faster and more precise.

Ryu or not, it'd have the issue of sometimes presenting digits the user
wasn't expecting, if the user is under the illusion that float is exact.
I'd rather document "this is always rounded to N digits" than have to
explain the cases where Ryu doesn't produce an "exact" result.
You don't have to look far for examples, eg

# select 1234567890::float4;
    float4     
---------------
 1.2345679e+09
(1 row)

# select '0.98765456'::float4;
   float4   
------------
 0.98765457
(1 row)

You have to keep in mind that what Ryu does (or claims to do anyway)
is produce the shortest decimal sequence that float4in will map back
to the same float4 bit pattern.  While this does often produce
"unsurprising" results, that is not guaranteed once you're past
six digits.

Now, I suppose there is something to be said for ensuring that
float::numeric and float::text::numeric produce the same answers,
which we'd get if we made float4_numeric and float8_numeric use
Ryu instead of the current method.  But that's not going to
change the fact that the OP is doing it wrong by expecting
exact results from what he's doing.

[ digs in archives... ]  The original thread about the Ryu patch [1]
considered this, and ultimately decided not to on the grounds
that float4_numeric is marked immutable and therefore we should
not change its behavior.  I'm not sure if that argument is
really irrefutable, but it's something to think about.

In any case, the JDBC list is not where to be complaining if you
want a server behavior change.

			regards, tom lane

[1] https://www.postgresql.org/message-id/flat/87r2el1bx6.fsf%40news-spur.riddles.org.uk





view thread (19+ messages)  latest in thread

Message-ID: <681507.1603233714@sss.pgh.pa.us>
Permalink:  ../681507.1603233714@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/681507.1603233714@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: tgl@sss.pgh.pa.us, sitnikov.vladimir@gmail.com, david.g.johnston@gmail.com, andreas@visena.com, Parameswaran.Thangavel@rsa.com
  Subject: Re: PostgresSQL 10 | Driver 42.2.5 | Float Conversion Issue
  In-Reply-To: <681507.1603233714@sss.pgh.pa.us>
  References: <CH2PR19MB3798B6096BD4EA60C2068367831F0@CH2PR19MB3798.namprd19.prod.outlook.com> <VisenaEmail.9.b226ab802321bcdc.17544a6d3e3@tc7-visena> <CH2PR19MB3798DAEA77750DD4F4CE67A0831F0@CH2PR19MB3798.namprd19.prod.outlook.com> <VisenaEmail.e.3213a432433c7179.17544c1d629@tc7-visena> <CAKFQuwbbYTc63HeEBPXcDzPU28Do4z+y9ZEwQKVFwCnbPP1FaQ@mail.gmail.com> <VisenaEmail.90.b09bf69bfcec8e52.17546ec4f83@tc7-visena> <652597.1603214274@sss.pgh.pa.us> <VisenaEmail.91.1593ba84a90d02a5.17547533c82@tc7-visena> <CAKFQuwYwsp7-5WUPsgg_ZpbtOOQ9kuvbEsD1LWLboz2qD80uwQ@mail.gmail.com> <VisenaEmail.98.ebf0ca280ce8e2b7.175476a101e@tc7-visena> <CAKFQuwYa=VsYuhCYEn+jCWc_s52h-oOVRzL696iQSJKHHbELOg@mail.gmail.com> <674136.1603223598@sss.pgh.pa.us> <CAB=Je-H8NiTt_+roUXzv=UiL6QWG-7QzihMVvpXrwyq8FLuo3w@mail.gmail.com> <675895.1603225986@sss.pgh.pa.us> <CAB=Je-GGS0c8im6suhe=zwvW21TTWyxJ=uXarzq6fLmVm-9eUA@mail.gmail.com> <681507.1603233714@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox