Re: floating point output

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: floating point output
Date: 2019-09-09 10:19:39
Message-ID: 20190909101939.GA11736@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2019-09-09 01:03:06 -0400, Tom Lane wrote:
> Rob Sargent <robjsargent(at)gmail(dot)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.

Cool. I looked into that some time ago, but never got around to
implement it.

> 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.

I agree in general, but I wonder whether it would be worthwhile to add
display formatting options to psql (something like "COLUMN foo FORMAT ..."
in Oracle's sqlplus), so that the user can decide to display a specific
column (or maybe all float numbers) as (for example) "%8.3f" or ".6e".

This is of course already possible by using to_char in the query (e.g.
to_char(f, '9999.999') or to_char(f, '9.999999EEEE')) but that is a bit
cumbersome.

hp

--
_ | Peter J. Holzer | we build much bigger, better disasters now
|_|_) | | because we have much more sophisticated
| | | hjp(at)hjp(dot)at | management tools.
__/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2019-09-09 10:46:32 Re: pgbouncer with ldap
Previous Message Laurenz Albe 2019-09-09 09:41:40 Re: pgbouncer with ldap