Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmQnK-0004V8-O2 for pgsql-docs@arkaria.postgresql.org; Mon, 28 Aug 2017 20:38:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dmQnK-0002r9-2f for pgsql-docs@arkaria.postgresql.org; Mon, 28 Aug 2017 20:38:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dmQmw-0002C8-UP for pgsql-docs@postgresql.org; Mon, 28 Aug 2017 20:37:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dmQmu-0008Oe-C5 for pgsql-docs@postgresql.org; Mon, 28 Aug 2017 20:37:37 +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 v7SKbYow021050; Mon, 28 Aug 2017 16:37:34 -0400 From: Tom Lane To: Erwin Brandstetter cc: pgsql-docs@postgresql.org Subject: Re: to_char(): 'FM' also suppresses *trailing* zeroes In-reply-to: References: Comments: In-reply-to Erwin Brandstetter message dated "Fri, 18 Aug 2017 02:01:39 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21048.1503952654.1@sss.pgh.pa.us> Date: Mon, 28 Aug 2017 16:37:34 -0400 Message-ID: <21049.1503952654@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org Erwin Brandstetter writes: > In Table 9-27. "Template Pattern Modifiers for Numeric Formatting" it says: > FM | prefix fill mode (suppress leading zeroes and padding blanks) | FM9999 > In fact, 'FM' also suppresses *trailing* zeroes after the comma. To fix, > this might be changed to: > suppress insignificant zeroes and padding blanks Not necessarily. A bit of experimentation says that it also matters whether you use "0" or "9" as the format character: regression=# select to_char(0.1, '0.9999'); to_char --------- 0.1000 (1 row) regression=# select to_char(0.1, 'FM0.9999'); to_char --------- 0.1 (1 row) regression=# select to_char(0.1, '0.9900'); to_char --------- 0.1000 (1 row) regression=# select to_char(0.1, 'FM0.9900'); to_char --------- 0.1000 (1 row) regression=# select to_char(0.1, 'FM00.99009'); to_char --------- 00.1000 (1 row) It's also worth noting the existing examples regression=# select to_char(-0.1, '99.99'); to_char --------- -.10 (1 row) regression=# select to_char(-0.1, 'FM99.99'); to_char --------- -.1 (1 row) So it appears to me that the bit you point out is flat out backwards; what FM actually suppresses is trailing zeroes not leading zeroes. I'm tempted to propose that in table 9-26, we need to write 9 digit position (can be dropped if insignificant) 0 digit position (cannot be dropped, even if insignificant) and then in 9-27 say FM fill mode: suppress trailing zeroes and padding spaces Also, in between those two tables, I see * 9 results in a value with the same number of digits as there are 9s. If a digit is not available it outputs a space. This seems outright wrong per the above examples, and in any case is not very useful since it doesn't explain the difference from "0". Perhaps rewrite as * 0 specifies a digit position that will always be printed, even if it contains a leading/trailing zero. 9 also specifies a digit position, but if it is a leading zero then it will be replaced by a space, while if it is a trailing zero and fill mode is specified then it will be deleted. (I wonder how closely that agrees with Oracle's behavior ...) regards, tom lane -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs