pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Rob Sargent <robjsargent@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: floating point output
Date: Mon, 09 Sep 2019 01:03:06 -0400
Message-ID: <3868.1568005386@sss.pgh.pa.us> (raw)
In-Reply-To: <3B44CDB3-56EA-4405-95A2-9405E565FFF0@gmail.com>
References: <2e1865c7-9ef3-e27f-e323-1659a5f129fc@gmail.com>
	<59e104ff-bb89-25d4-2c50-9e15b4655980@aklaver.com>
	<EB5A6A4C-F58A-4055-82F4-1E76CD675B4C@gmail.com>
	<3B44CDB3-56EA-4405-95A2-9405E565FFF0@gmail.com>

Rob Sargent <robjsargent@gmail.com> writes:
> Below I show a floating point column from a recent query.  

> Here's my guess at what's happening in the formatting:
>   1) scientific notation if smaller than 1.0e-04 (I’m not in the very-much-larger-than-one world)
>   2) 15 digits after the most signicant 0
>   3) remove trailing zeros

> I may be alone in this but I find the presentation messy and that's
> unusual in the PostgreSQL world.

In released versions of Postgres, float8out basically devolves to
sprintf with "%.15g" format, and the above is what POSIX says that
should do.

As of v12, we'll use the "Ryu" output algorithm, which adjusts
the number of displayed digits to ensure that the value will
re-load exactly by default.  I'm afraid that will probably make
your complaint about variable numbers of digits worse not better.
It's unlikely anybody will entertain an argument to undo it,
though, because (a) Ryu is faster than the old code, and (b) it's
hard to argue against ensuring that output/input preserves values.

You might consider using type "numeric" if you find truncation
of low-order zeroes undesirable.

			regards, tom lane





view thread (7+ messages)  latest in thread

Message-ID: <3868.1568005386@sss.pgh.pa.us>
Permalink:  ../3868.1568005386@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3868.1568005386@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, robjsargent@gmail.com, adrian.klaver@aklaver.com
  Subject: Re: floating point output
  In-Reply-To: <3868.1568005386@sss.pgh.pa.us>
  References: <2e1865c7-9ef3-e27f-e323-1659a5f129fc@gmail.com> <59e104ff-bb89-25d4-2c50-9e15b4655980@aklaver.com> <EB5A6A4C-F58A-4055-82F4-1E76CD675B4C@gmail.com> <3B44CDB3-56EA-4405-95A2-9405E565FFF0@gmail.com> <3868.1568005386@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