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 1i7Gmm-0003sb-Fs for pgsql-general@arkaria.postgresql.org; Mon, 09 Sep 2019 10:20:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i7Gml-00040c-Bc for pgsql-general@arkaria.postgresql.org; Mon, 09 Sep 2019 10:20:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i7Glu-0006wK-0d for pgsql-general@lists.postgresql.org; Mon, 09 Sep 2019 10:19:46 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i7Glq-0004MS-BS for pgsql-general@lists.postgresql.org; Mon, 09 Sep 2019 10:19:45 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 2C80A7B1; Mon, 9 Sep 2019 12:19:39 +0200 (CEST) Date: Mon, 9 Sep 2019 12:19:39 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: floating point output Message-ID: <20190909101939.GA11736@hjp.at> References: <2e1865c7-9ef3-e27f-e323-1659a5f129fc@gmail.com> <59e104ff-bb89-25d4-2c50-9e15b4655980@aklaver.com> <3B44CDB3-56EA-4405-95A2-9405E565FFF0@gmail.com> <3868.1568005386@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ikeVEW9yuYc//A+q" Content-Disposition: inline In-Reply-To: <3868.1568005386@sss.pgh.pa.us> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --ikeVEW9yuYc//A+q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-09-09 01:03:06 -0400, Tom Lane wrote: > Rob Sargent writes: > > Below I show a floating point column from a recent query. =20 >=20 > > 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 th= e very-much-larger-than-one world) > > 2) 15 digits after the most signicant 0 > > 3) remove trailing zeros >=20 > > I may be alone in this but I find the presentation messy and that's > > unusual in the PostgreSQL world. >=20 > In released versions of Postgres, float8out basically devolves to > sprintf with "%.15g" format, and the above is what POSIX says that > should do. >=20 > 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.=20 hp --=20 _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson --ikeVEW9yuYc//A+q Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl12JzUACgkQ8g5IURL+ KF3liA//SlLntmyVCHmmKk0eHzQy7lEk292+IwaBV1+sHBQIsoPaET7LrhwMTw+o rvVHQJsP83a+Rte1NEO+MoZn/nW3Fm/Pp8wb2I9RbqpwxSN2bfZPTXDDOafYMEWL ffQrsNixK8FJ/O6v/UQwYnYMl53W/C+iJov24Euvgxde+Styxx30/XIFingoIel9 sG0Px8RKYcI8LDqQeSAKQTWvwmqqwVhUPF3XEYBx5qUpwx/oDI4BMVmv3TktU4Q6 yqbSPyiBXnmJX/6RWHFr7LG7ZtQtroWMlBMEu7X4qNlwp/JWOuKqHSJwQM+yA/oE PRRhlKaB9rjMPBM1Q+COFHzao7HKY4Rx9fQdYMWj+u2jC1WEvvpyZOOwJTEUNMiS 0I7odQer+i52dFDzTGNsjaNPFOS2BuTWbdkhgB0A22DKRzxlorNoi3fhZoDeRCz/ yRYhGPoMD7VZUTc8eOAq94a4pv8nQuN5j+QabO3vqYyFNmnQmAkjnXm4skaeJVRA Lk0l1MOvhemWlhIM549jwyeJX/tNFANgJdbX4UEuDy/AbWzdYpnd8sVrUI9/TWMD 4cROFuLx6z6KO1twkdVHRHw2brVePWkJjOuexW683t2Tm/hBR/siNDCUqm7jKZm1 64HWA3MhiMwYo4HWdy4vwYmtRVaaHPi05Ma8/UsGJpcHSea7X6c= =5Do+ -----END PGP SIGNATURE----- --ikeVEW9yuYc//A+q--