Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dbc7a7d

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 254bb39 commit dbc7a7d

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
@@ -6277,19 +6277,19 @@ SELECT regexp_matches('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
62776277
<tbody>
62786278
<row>
62796279
<entry><literal>9</literal></entry>
6280-
<entry>value with the specified number of digits</entry>
6280+
<entry>digit position (can be dropped if insignificant)</entry>
62816281
</row>
62826282
<row>
62836283
<entry><literal>0</literal></entry>
6284-
<entry>value with leading zeros</entry>
6284+
<entry>digit position (will not be dropped, even if insignificant)</entry>
62856285
</row>
62866286
<row>
62876287
<entry><literal>.</literal> (period)</entry>
62886288
<entry>decimal point</entry>
62896289
</row>
62906290
<row>
62916291
<entry><literal>,</literal> (comma)</entry>
6292-
<entry>group (thousand) separator</entry>
6292+
<entry>group (thousands) separator</entry>
62936293
</row>
62946294
<row>
62956295
<entry><literal>PR</literal></entry>
@@ -6347,25 +6347,50 @@ SELECT regexp_matches('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
63476347
Usage notes for numeric formatting:
63486348

63496349
<itemizedlist>
6350+
<listitem>
6351+
<para>
6352+
<literal>0</> specifies a digit position that will always be printed,
6353+
even if it contains a leading/trailing zero. <literal>9</> also
6354+
specifies a digit position, but if it is a leading zero then it will
6355+
be replaced by a space, while if it is a trailing zero and fill mode
6356+
is specified then it will be deleted. (For <function>to_number()</>,
6357+
these two pattern characters are equivalent.)
6358+
</para>
6359+
</listitem>
6360+
6361+
<listitem>
6362+
<para>
6363+
The pattern characters <literal>S</>, <literal>L</>, <literal>D</>,
6364+
and <literal>G</> represent the sign, currency symbol, decimal point,
6365+
and thousands separator characters defined by the current locale
6366+
(see <xref linkend="guc-lc-monetary">
6367+
and <xref linkend="guc-lc-numeric">). The pattern characters period
6368+
and comma represent those exact characters, with the meanings of
6369+
decimal point and thousands separator, regardless of locale.
6370+
</para>
6371+
</listitem>
6372+
6373+
<listitem>
6374+
<para>
6375+
If no explicit provision is made for a sign
6376+
in <function>to_char()</>'s pattern, one column will be reserved for
6377+
the sign, and it will be anchored to (appear just left of) the
6378+
number. If <literal>S</> appears just left of some <literal>9</>'s,
6379+
it will likewise be anchored to the number.
6380+
</para>
6381+
</listitem>
6382+
63506383
<listitem>
63516384
<para>
63526385
A sign formatted using <literal>SG</literal>, <literal>PL</literal>, or
63536386
<literal>MI</literal> is not anchored to
63546387
the number; for example,
63556388
<literal>to_char(-12, 'MI9999')</literal> produces <literal>'-&nbsp;&nbsp;12'</literal>
63566389
but <literal>to_char(-12, 'S9999')</literal> produces <literal>'&nbsp;&nbsp;-12'</literal>.
6357-
The Oracle implementation does not allow the use of
6390+
(The Oracle implementation does not allow the use of
63586391
<literal>MI</literal> before <literal>9</literal>, but rather
63596392
requires that <literal>9</literal> precede
6360-
<literal>MI</literal>.
6361-
</para>
6362-
</listitem>
6363-
6364-
<listitem>
6365-
<para>
6366-
<literal>9</literal> results in a value with the same number of
6367-
digits as there are <literal>9</literal>s. If a digit is
6368-
not available it outputs a space.
6393+
<literal>MI</literal>.)
63696394
</para>
63706395
</listitem>
63716396

@@ -6412,8 +6437,8 @@ SELECT regexp_matches('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
64126437

64136438
<para>
64146439
Certain modifiers can be applied to any template pattern to alter its
6415-
behavior. For example, <literal>FM9999</literal>
6416-
is the <literal>9999</literal> pattern with the
6440+
behavior. For example, <literal>FM99.99</literal>
6441+
is the <literal>99.99</literal> pattern with the
64176442
<literal>FM</literal> modifier.
64186443
<xref linkend="functions-formatting-numericmod-table"> shows the
64196444
modifier patterns for numeric formatting.
@@ -6432,8 +6457,8 @@ SELECT regexp_matches('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
64326457
<tbody>
64336458
<row>
64346459
<entry><literal>FM</literal> prefix</entry>
6435-
<entry>fill mode (suppress leading zeroes and padding blanks)</entry>
6436-
<entry><literal>FM9999</literal></entry>
6460+
<entry>fill mode (suppress trailing zeroes and padding blanks)</entry>
6461+
<entry><literal>FM99.99</literal></entry>
64376462
</row>
64386463
<row>
64396464
<entry><literal>TH</literal> suffix</entry>
@@ -6480,6 +6505,10 @@ SELECT regexp_matches('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
64806505
<entry><literal>to_char(-0.1, 'FM9.99')</literal></entry>
64816506
<entry><literal>'-.1'</literal></entry>
64826507
</row>
6508+
<row>
6509+
<entry><literal>to_char(-0.1, 'FM90.99')</literal></entry>
6510+
<entry><literal>'-0.1'</literal></entry>
6511+
</row>
64836512
<row>
64846513
<entry><literal>to_char(0.1, '0.9')</literal></entry>
64856514
<entry><literal>'&nbsp;0.1'</literal></entry>

0 commit comments

Comments
 (0)