Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6A1D3B5DC13 for ; Tue, 20 Sep 2011 14:49:36 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 59221-05 for ; Tue, 20 Sep 2011 17:49:30 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id E79A5B5DBF2 for ; Tue, 20 Sep 2011 14:49:29 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p8KHnSWr011126; Tue, 20 Sep 2011 13:49:28 -0400 (EDT) To: "Chris Gernon" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6217: to_char() gives incorrect output for very small float values In-reply-to: <201109201717.p8KHHlZU087195@wwwmaster.postgresql.org> References: <201109201717.p8KHHlZU087195@wwwmaster.postgresql.org> Comments: In-reply-to "Chris Gernon" message dated "Tue, 20 Sep 2011 17:17:47 +0000" Date: Tue, 20 Sep 2011 13:49:28 -0400 Message-ID: <11125.1316540968@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/121 X-Sequence-Number: 31138 "Chris Gernon" writes: > CREATE TABLE t ( > id serial, > f double precision, > CONSTRAINT t_pk PRIMARY KEY (id) > ); > INSERT INTO t (f) VALUES (0.0000000000000000000000000000000563219288); > ---------------------------------------- > SELECT to_char(f, > 'FM999990.99999999999999999999999999999999999999999999999999') FROM t WHERE > id = 1; > Expected Output: > 0.0000000000000000000000000000000563219288 > Actual Output: > 0. My immediate reaction to that is that float8 values don't have 57 digits of precision. If you are expecting that format string to do something useful you should be applying it to a numeric column not a double precision one. It's possible that we can kluge things to make this particular case work like you are expecting, but there are always going to be similar-looking cases that can't work because the precision just isn't there. (In a quick look at the code, the reason you just get "0." is that it's rounding off after 15 digits to ensure it doesn't print garbage. Maybe it could be a bit smarter for cases where the value is very much smaller than 1, but it wouldn't be a simple change.) regards, tom lane