From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | "Thangavel, Parameswaran" <Parameswaran(dot)Thangavel(at)rsa(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>, Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> |
Subject: | Re: PostgresSQL 10 | Driver 42.2.5 | Float Conversion Issue |
Date: | 2020-10-21 00:45:02 |
Message-ID: | 20201021004502.ebggjsmjdz2r4zkq@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Hi,
On 2020-10-20 09:50:46 -0700, David G. Johnston wrote:
> So, confirming the following query result on head.
>
> select '1234567'::float4::numeric; -- 1234570
The reason this happens is that the float[48]->numeric casts are
implemented by converting the float value to string using
FLT_DIG/DBL_DIG, and then reading that back as a string. Unfortunately
that's pretty bogus - FLT_DIG / DBL_DIG are extremely pessimistic; as it
turns out rounding a few digits beyond the decimal point isn't the same
as before the decimal point.
Unfortunately this can't easily be changed, as any such change would
e.g. break indexes that include float->numeric casts. Including across
major versions, due to pg_upgrade.
For text this is not a problem anymore since v12 (with default settings,
i.e. extra_float_digits > 0), because we now use ryu for those
conversions. But we can't depend extra_float_digits in the case of
float->numeric casts, because it's an immutable function :/
Thanks to Andrew Gierth for some pointers.
Some discussion links:
https://www.postgresql.org/message-id/874lagotif.fsf%40news-spur.riddles.org.uk
https://postgr.es/m/26443.1571712071%40sss.pgh.pa.us
https://www.postgresql.org/message-id/87y37qmwee.fsf%40news-spur.riddles.org.uk
Greetings,
Andres Freund
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2020-10-21 01:12:44 | Re: ECPG bug: "unterminated quoted identifier" |
Previous Message | 1250kv | 2020-10-20 22:51:09 | Re: ECPG bug: "unterminated quoted identifier" |