Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i7Bpd-0008Vc-OM for pgsql-general@arkaria.postgresql.org; Mon, 09 Sep 2019 05:03:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i7Bpb-0004NT-Bb for pgsql-general@arkaria.postgresql.org; Mon, 09 Sep 2019 05:03:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i7Bpa-0003zY-S4 for pgsql-general@lists.postgresql.org; Mon, 09 Sep 2019 05:03:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i7BpX-0005ZM-ON for pgsql-general@postgresql.org; Mon, 09 Sep 2019 05:03:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x89536gU003869; Mon, 9 Sep 2019 01:03:06 -0400 From: Tom Lane To: Rob Sargent cc: Adrian Klaver , "pgsql-general@postgresql.org" Subject: Re: floating point output 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> <3B44CDB3-56EA-4405-95A2-9405E565FFF0@gmail.com> Comments: In-reply-to Rob Sargent message dated "Sun, 08 Sep 2019 22:16:55 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3862.1568005386.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 09 Sep 2019 01:03:06 -0400 Message-ID: <3868.1568005386@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rob Sargent 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=E2=80=99m 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