Re: [DOCS] to_char(): 'FM' also suppresses *trailing* zeroes

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [DOCS] to_char(): 'FM' also suppresses *trailing* zeroes
Дата
Msg-id 21049.1503952654@sss.pgh.pa.us
обсуждение исходный текст
Ответ на [DOCS] to_char(): 'FM' also suppresses *trailing* zeroes  (Erwin Brandstetter <brsaweda@gmail.com>)
Ответы Re: [DOCS] to_char(): 'FM' also suppresses *trailing* zeroes  (Erwin Brandstetter <brsaweda@gmail.com>)
Список pgsql-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


В списке pgsql-docs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [DOCS] Requesting clarifying details on extract(epoch from timestamp)
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [DOCS] Failing example for to_number()