Commit 70d8a2c2 authored by Bruce Momjian's avatar Bruce Momjian

Honor to_char() "FM" specification in YYY, YY, and Y; it was already

honored by YYYY.  Also document Oracle "toggle" FM behavior.

Per report from Guy Rouillier
parent 55ea144a
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.502 2010/02/12 17:33:19 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.503 2010/02/16 21:18:01 momjian Exp $ -->
<chapter id="functions">
<title>Functions and Operators</title>
......@@ -5174,7 +5174,11 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<para>
<literal>FM</literal> suppresses leading zeroes and trailing blanks
that would otherwise be added to make the output of a pattern be
fixed-width.
fixed-width. In <productname>PostgreSQL</productname>,
<literal>FM</literal> modifies only the next specification, while in
Oracle <literal>FM</literal> affects all subsequent
specifications, and repeated <literal>FM</literal> modifiers
toggle fill mode on and off.
</para>
</listitem>
......
/* -----------------------------------------------------------------------
* formatting.c
*
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.162 2010/01/02 16:57:53 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.163 2010/02/16 21:18:01 momjian Exp $
*
*
* Portions Copyright (c) 1999-2010, PostgreSQL Global Development Group
......@@ -515,6 +515,7 @@ do { \
#define S_th(_s) (((_s) & DCH_S_th) ? 1 : 0)
#define S_TH_TYPE(_s) (((_s) & DCH_S_TH) ? TH_UPPER : TH_LOWER)
/* Oracle toggles FM behavior, we don't; see docs. */
#define S_FM(_s) (((_s) & DCH_S_FM) ? 1 : 0)
#define S_SP(_s) (((_s) & DCH_S_SP) ? 1 : 0)
#define S_TM(_s) (((_s) & DCH_S_TM) ? 1 : 0)
......@@ -2411,28 +2412,30 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
break;
case DCH_YYY:
case DCH_IYY:
snprintf(buff, sizeof(buff), "%03d",
snprintf(buff, sizeof(buff), "%0*d",
S_FM(n->suffix) ? 0 : 3,
n->key->id == DCH_YYY ?
ADJUST_YEAR(tm->tm_year, is_interval) :
ADJUST_YEAR(date2isoyear(tm->tm_year,
tm->tm_mon, tm->tm_mday),
is_interval));
i = strlen(buff);
strcpy(s, buff + (i - 3));
strcpy(s, buff + (i > 3 ? i - 3 : 0));
if (S_THth(n->suffix))
str_numth(s, s, S_TH_TYPE(n->suffix));
s += strlen(s);
break;
case DCH_YY:
case DCH_IY:
snprintf(buff, sizeof(buff), "%02d",
snprintf(buff, sizeof(buff), "%0*d",
S_FM(n->suffix) ? 0 : 2,
n->key->id == DCH_YY ?
ADJUST_YEAR(tm->tm_year, is_interval) :
ADJUST_YEAR(date2isoyear(tm->tm_year,
tm->tm_mon, tm->tm_mday),
is_interval));
i = strlen(buff);
strcpy(s, buff + (i - 2));
strcpy(s, buff + (i > 2 ? i - 2 : 0));
if (S_THth(n->suffix))
str_numth(s, s, S_TH_TYPE(n->suffix));
s += strlen(s);
......@@ -2446,7 +2449,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
tm->tm_mon, tm->tm_mday),
is_interval));
i = strlen(buff);
strcpy(s, buff + (i - 1));
strcpy(s, buff + (i > 1 ? i - 1 : 0));
if (S_THth(n->suffix))
str_numth(s, s, S_TH_TYPE(n->suffix));
s += strlen(s);
......
......@@ -1063,8 +1063,8 @@ SELECT '' AS to_char_4, to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM
| 1,997 1997 997 97 7 20 1 2 7 45 14 6 2450494
| 1,997 1997 997 97 7 20 1 2 7 46 15 7 2450495
| 1,997 1997 997 97 7 20 1 2 7 47 16 1 2450496
| 0,097 97 097 97 7 1 1 2 7 47 16 3 1686042
| 0,097 97 097 97 7 1 1 2 7 47 16 7 1756536
| 0,097 97 97 97 7 1 1 2 7 47 16 3 1686042
| 0,097 97 97 97 7 1 1 2 7 47 16 7 1756536
| 0,597 597 597 97 7 6 1 2 7 47 16 5 1939157
| 1,097 1097 097 97 7 11 1 2 7 47 16 3 2121778
| 1,697 1697 697 97 7 17 1 2 7 47 16 7 2340924
......@@ -1561,8 +1561,8 @@ SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID')
| 1997 997 97 7 7 47 5
| 1997 997 97 7 7 48 6
| 1997 997 97 7 7 49 7
| 97 097 97 7 7 44 2
| 97 097 97 7 7 48 6
| 97 97 97 7 7 44 2
| 97 97 97 7 7 48 6
| 597 597 97 7 7 46 4
| 1097 097 97 7 7 44 2
| 1697 697 97 7 7 48 6
......
......@@ -1148,8 +1148,8 @@ SELECT '' AS to_char_4, to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM
| 1,997 1997 997 97 7 20 1 2 7 45 14 6 2450494
| 1,997 1997 997 97 7 20 1 2 7 46 15 7 2450495
| 1,997 1997 997 97 7 20 1 2 7 47 16 1 2450496
| 0,097 97 097 97 7 1 1 2 7 47 16 3 1686042
| 0,097 97 097 97 7 1 1 2 7 47 16 7 1756536
| 0,097 97 97 97 7 1 1 2 7 47 16 3 1686042
| 0,097 97 97 97 7 1 1 2 7 47 16 7 1756536
| 0,597 597 597 97 7 6 1 2 7 47 16 5 1939157
| 1,097 1097 097 97 7 11 1 2 7 47 16 3 2121778
| 1,697 1697 697 97 7 17 1 2 7 47 16 7 2340924
......@@ -1655,8 +1655,8 @@ SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID')
| 1997 997 97 7 7 47 5
| 1997 997 97 7 7 48 6
| 1997 997 97 7 7 49 7
| 97 097 97 7 7 44 2
| 97 097 97 7 7 48 6
| 97 97 97 7 7 44 2
| 97 97 97 7 7 48 6
| 597 597 97 7 7 46 4
| 1097 097 97 7 7 44 2
| 1697 697 97 7 7 48 6
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment