From: Tom Lane <tgl@sss.pgh.pa.us>
To: Erwin Brandstetter <brsaweda@gmail.com>
Cc: pgsql-docs@postgresql.org
Subject: Re: to_char(): 'FM' also suppresses *trailing* zeroes
Date: Mon, 28 Aug 2017 16:37:34 -0400
Message-ID: <21049.1503952654@sss.pgh.pa.us> (raw)
In-Reply-To: <CAGHENJ7jgRbTn6nf48xNZ=FHgL2WQ4X8mYsUAU57f-vq8PubEw@mail.gmail.com>
References: <CAGHENJ7jgRbTn6nf48xNZ=FHgL2WQ4X8mYsUAU57f-vq8PubEw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-docs>
Erwin Brandstetter <brsaweda@gmail.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-docs@postgresql.org
Cc: tgl@sss.pgh.pa.us, brsaweda@gmail.com
Subject: Re: to_char(): 'FM' also suppresses *trailing* zeroes
In-Reply-To: <21049.1503952654@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox