Skip to content

Commit ce5dcf5

Browse files
committed
Improve docs about numeric formatting patterns (to_char/to_number).
The explanation about "0" versus "9" format characters was confusing and arguably wrong; the discussion of sign handling wasn't very good either. Notably, while it's accurate to say that "FM" strips leading zeroes in date/time values, what it really does with numeric values is to strip *trailing* zeroes, and then only if you wrote "9" rather than "0". Per gripes from Erwin Brandstetter. Discussion: https://postgr.es/m/CAGHENJ7jgRbTn6nf48xNZ=FHgL2WQ4X8mYsUAU57f-vq8PubEw@mail.gmail.com Discussion: https://postgr.es/m/CAGHENJ45ymd=GOCu1vwV9u7GmCR80_5tW0fP9C_gJKbruGMHvQ@mail.gmail.com
1 parent dc4f356 commit ce5dcf5

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

doc/src/sgml/func.sgml

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6351,19 +6351,19 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
63516351
<tbody>
63526352
<row>
63536353
<entry><literal>9</literal></entry>
6354-
<entry>value with the specified number of digits</entry>
6354+
<entry>digit position (can be dropped if insignificant)</entry>
63556355
</row>
63566356
<row>
63576357
<entry><literal>0</literal></entry>
6358-
<entry>value with leading zeros</entry>
6358+
<entry>digit position (will not be dropped, even if insignificant)</entry>
63596359
</row>
63606360
<row>
63616361
<entry><literal>.</literal> (period)</entry>
63626362
<entry>decimal point</entry>
63636363
</row>
63646364
<row>
63656365
<entry><literal>,</literal> (comma)</entry>
6366-
<entry>group (thousand) separator</entry>
6366+
<entry>group (thousands) separator</entry>
63676367
</row>
63686368
<row>
63696369
<entry><literal>PR</literal></entry>
@@ -6421,25 +6421,50 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
64216421
Usage notes for numeric formatting:
64226422

64236423
<itemizedlist>
6424+
<listitem>
6425+
<para>
6426+
<literal>0</> specifies a digit position that will always be printed,
6427+
even if it contains a leading/trailing zero. <literal>9</> also
6428+
specifies a digit position, but if it is a leading zero then it will
6429+
be replaced by a space, while if it is a trailing zero and fill mode
6430+
is specified then it will be deleted. (For <function>to_number()</>,
6431+
these two pattern characters are equivalent.)
6432+
</para>
6433+
</listitem>
6434+
6435+
<listitem>
6436+
<para>
6437+
The pattern characters <literal>S</>, <literal>L</>, <literal>D</>,
6438+
and <literal>G</> represent the sign, currency symbol, decimal point,
6439+
and thousands separator characters defined by the current locale
6440+
(see <xref linkend="guc-lc-monetary">
6441+
and <xref linkend="guc-lc-numeric">). The pattern characters period
6442+
and comma represent those exact characters, with the meanings of
6443+
decimal point and thousands separator, regardless of locale.
6444+
</para>
6445+
</listitem>
6446+
6447+
<listitem>
6448+
<para>
6449+
If no explicit provision is made for a sign
6450+
in <function>to_char()</>'s pattern, one column will be reserved for
6451+
the sign, and it will be anchored to (appear just left of) the
6452+
number. If <literal>S</> appears just left of some <literal>9</>'s,
6453+
it will likewise be anchored to the number.
6454+
</para>
6455+
</listitem>
6456+
64246457
<listitem>
64256458
<para>
64266459
A sign formatted using <literal>SG</literal>, <literal>PL</literal>, or
64276460
<literal>MI</literal> is not anchored to
64286461
the number; for example,
64296462
<literal>to_char(-12, 'MI9999')</literal> produces <literal>'-&nbsp;&nbsp;12'</literal>
64306463
but <literal>to_char(-12, 'S9999')</literal> produces <literal>'&nbsp;&nbsp;-12'</literal>.
6431-
The Oracle implementation does not allow the use of
6464+
(The Oracle implementation does not allow the use of
64326465
<literal>MI</literal> before <literal>9</literal>, but rather
64336466
requires that <literal>9</literal> precede
6434-
<literal>MI</literal>.
6435-
</para>
6436-
</listitem>
6437-
6438-
<listitem>
6439-
<para>
6440-
<literal>9</literal> results in a value with the same number of
6441-
digits as there are <literal>9</literal>s. If a digit is
6442-
not available it outputs a space.
6467+
<literal>MI</literal>.)
64436468
</para>
64446469
</listitem>
64456470

@@ -6486,8 +6511,8 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
64866511

64876512
<para>
64886513
Certain modifiers can be applied to any template pattern to alter its
6489-
behavior. For example, <literal>FM9999</literal>
6490-
is the <literal>9999</literal> pattern with the
6514+
behavior. For example, <literal>FM99.99</literal>
6515+
is the <literal>99.99</literal> pattern with the
64916516
<literal>FM</literal> modifier.
64926517
<xref linkend="functions-formatting-numericmod-table"> shows the
64936518
modifier patterns for numeric formatting.
@@ -6506,8 +6531,8 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
65066531
<tbody>
65076532
<row>
65086533
<entry><literal>FM</literal> prefix</entry>
6509-
<entry>fill mode (suppress leading zeroes and padding blanks)</entry>
6510-
<entry><literal>FM9999</literal></entry>
6534+
<entry>fill mode (suppress trailing zeroes and padding blanks)</entry>
6535+
<entry><literal>FM99.99</literal></entry>
65116536
</row>
65126537
<row>
65136538
<entry><literal>TH</literal> suffix</entry>
@@ -6554,6 +6579,10 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
65546579
<entry><literal>to_char(-0.1, 'FM9.99')</literal></entry>
65556580
<entry><literal>'-.1'</literal></entry>
65566581
</row>
6582+
<row>
6583+
<entry><literal>to_char(-0.1, 'FM90.99')</literal></entry>
6584+
<entry><literal>'-0.1'</literal></entry>
6585+
</row>
65576586
<row>
65586587
<entry><literal>to_char(0.1, '0.9')</literal></entry>
65596588
<entry><literal>'&nbsp;0.1'</literal></entry>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy