Re: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type? - Mailing list pgsql-general

From Tom Lane
Subject Re: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?
Date
Msg-id 3259196.1697688771@sss.pgh.pa.us
Whole thread Raw
In response to How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?  (毛毛 <krave@163.com>)
Responses Re: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?
List pgsql-general
=?GBK?B?w6vDqw==?= <krave@163.com> writes:
> Do we have a rule by follow which one can accurately info the output of a SELECT statment FROM a table with
floating-pointdata type? 

The goal of our floating-point output functions is to produce
the shortest representation from which the stored value could
be recovered exactly.  It's not unusual for that to require
two or three decimal digits more than the nominal precision.
Keep in mind that the nominal precision, such as 6 digits for
float4, is a *lower bound* on the number of decimal digits
that will be stored accurately, whereas supporting exact
round-trip I/O requires an *upper bound* number of digits.

In short, no, there is not a trivial way to predict the
number of digits emitted.  If you have a problem with that,
maybe you should be using type numeric instead.

You can find more info by looking around for info about the
Ryū float output algorithm, eg here:

https://github.com/ulfjack/ryu

            regards, tom lane



pgsql-general by date:

Previous
From: 毛毛
Date:
Subject: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?
Next
From: "David G. Johnston"
Date:
Subject: Re: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?