pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: 毛毛 <krave@163.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?
Date: Thu, 19 Oct 2023 00:12:51 -0400
Message-ID: <3259196.1697688771@sss.pgh.pa.us> (raw)
In-Reply-To: <10b02a08.28b4.18b460a2f09.Coremail.krave@163.com>
References: <10b02a08.28b4.18b460a2f09.Coremail.krave@163.com>

=?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-point data 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





view thread (5+ messages)  latest in thread

Message-ID: <3259196.1697688771@sss.pgh.pa.us>
Permalink:  ../3259196.1697688771@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3259196.1697688771@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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, krave@163.com
  Subject: Re: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?
  In-Reply-To: <3259196.1697688771@sss.pgh.pa.us>
  References: <10b02a08.28b4.18b460a2f09.Coremail.krave@163.com> <3259196.1697688771@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