-<!-- $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>
<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
#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)
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);
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);
| 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
| 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
| 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
| 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