60#ifdef DEBUG_TO_FROM_CHAR
61#define DEBUG_elog_output DEBUG3
97#define KeyWord_INDEX_SIZE ('~' - ' ')
98#define KeyWord_INDEX_FILTER(_c) ((_c) <= ' ' || (_c) >= '~' ? 0 : 1)
103#define DCH_MAX_ITEM_SIZ 12
104#define NUM_MAX_ITEM_SIZ 8
170 "January",
"February",
"March",
"April",
"May",
"June",
"July",
171 "August",
"September",
"October",
"November",
"December",
NULL
175 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
NULL
185#define ADJUST_YEAR(year, is_interval) ((is_interval) ? (year) : ((year) <= 0 ? -((year) - 1) : (year)))
187#define A_D_STR "A.D."
188#define a_d_STR "a.d."
192#define B_C_STR "B.C."
193#define b_c_STR "b.c."
213#define A_M_STR "A.M."
214#define a_m_STR "a.m."
218#define P_M_STR "P.M."
219#define p_m_STR "p.m."
242{
"XII",
"XI",
"X",
"IX",
"VIII",
"VII",
"VI",
"V",
"IV",
"III",
"II",
"I",
NULL};
245{
"xii",
"xi",
"x",
"ix",
"viii",
"vii",
"vi",
"v",
"iv",
"iii",
"ii",
"i",
NULL};
250static const char *
const rm1[] = {
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX",
NULL};
251static const char *
const rm10[] = {
"X",
"XX",
"XXX",
"XL",
"L",
"LX",
"LXX",
"LXXX",
"XC",
NULL};
252static const char *
const rm100[] = {
"C",
"CC",
"CCC",
"CD",
"D",
"DC",
"DCC",
"DCCC",
"CM",
NULL};
258#define IS_VALID_SUB_COMB(curr, next) \
259 (((curr) == 'I' && ((next) == 'V' || (next) == 'X')) || \
260 ((curr) == 'X' && ((next) == 'L' || (next) == 'C')) || \
261 ((curr) == 'C' && ((next) == 'D' || (next) == 'M')))
266#define ROMAN_VAL(r) \
273 (r) == 'M' ? 1000 : 0)
278#define MAX_ROMAN_LEN 15
283static const char *
const numTH[] = {
"ST",
"ND",
"RD",
"TH",
NULL};
284static const char *
const numth[] = {
"st",
"nd",
"rd",
"th",
NULL};
321#define NUM_F_DECIMAL (1 << 1)
322#define NUM_F_LDECIMAL (1 << 2)
323#define NUM_F_ZERO (1 << 3)
324#define NUM_F_BLANK (1 << 4)
325#define NUM_F_FILLMODE (1 << 5)
326#define NUM_F_LSIGN (1 << 6)
327#define NUM_F_BRACKET (1 << 7)
328#define NUM_F_MINUS (1 << 8)
329#define NUM_F_PLUS (1 << 9)
330#define NUM_F_ROMAN (1 << 10)
331#define NUM_F_MULTI (1 << 11)
332#define NUM_F_PLUS_POST (1 << 12)
333#define NUM_F_MINUS_POST (1 << 13)
334#define NUM_F_EEEE (1 << 14)
339#define IS_DECIMAL(_f) ((_f)->flag & NUM_F_DECIMAL)
340#define IS_LDECIMAL(_f) ((_f)->flag & NUM_F_LDECIMAL)
341#define IS_ZERO(_f) ((_f)->flag & NUM_F_ZERO)
342#define IS_BLANK(_f) ((_f)->flag & NUM_F_BLANK)
343#define IS_FILLMODE(_f) ((_f)->flag & NUM_F_FILLMODE)
344#define IS_BRACKET(_f) ((_f)->flag & NUM_F_BRACKET)
345#define IS_MINUS(_f) ((_f)->flag & NUM_F_MINUS)
346#define IS_LSIGN(_f) ((_f)->flag & NUM_F_LSIGN)
347#define IS_PLUS(_f) ((_f)->flag & NUM_F_PLUS)
348#define IS_ROMAN(_f) ((_f)->flag & NUM_F_ROMAN)
349#define IS_MULTI(_f) ((_f)->flag & NUM_F_MULTI)
350#define IS_EEEE(_f) ((_f)->flag & NUM_F_EEEE)
369#define DCH_CACHE_OVERHEAD \
370 MAXALIGN(sizeof(bool) + sizeof(int))
371#define NUM_CACHE_OVERHEAD \
372 MAXALIGN(sizeof(bool) + sizeof(int) + sizeof(NUMDesc))
374#define DCH_CACHE_SIZE \
375 ((2048 - DCH_CACHE_OVERHEAD) / (sizeof(FormatNode) + sizeof(char)) - 1)
376#define NUM_CACHE_SIZE \
377 ((1024 - NUM_CACHE_OVERHEAD) / (sizeof(FormatNode) + sizeof(char)) - 1)
379#define DCH_CACHE_ENTRIES 20
380#define NUM_CACHE_ENTRIES 20
454#ifdef DEBUG_TO_FROM_CHAR
455#define DEBUG_TMFC(_X) \
456 elog(DEBUG_elog_output, "TMFC:\nmode %d\nhh %d\npm %d\nmi %d\nss %d\nssss %d\nd %d\ndd %d\nddd %d\nmm %d\nms: %d\nyear %d\nbc %d\nww %d\nw %d\ncc %d\nj %d\nus: %d\nyysz: %d\nclock: %d", \
457 (_X)->mode, (_X)->hh, (_X)->pm, (_X)->mi, (_X)->ss, (_X)->ssss, \
458 (_X)->d, (_X)->dd, (_X)->ddd, (_X)->mm, (_X)->ms, (_X)->year, \
459 (_X)->bc, (_X)->ww, (_X)->w, (_X)->cc, (_X)->j, (_X)->us, \
460 (_X)->yysz, (_X)->clock_12_hour)
461#define DEBUG_TM(_X) \
462 elog(DEBUG_elog_output, "TM:\nsec %d\nyear %d\nmin %d\nwday %d\nhour %d\nyday %d\nmday %d\nnisdst %d\nmon %d\n",\
463 (_X)->tm_sec, (_X)->tm_year,\
464 (_X)->tm_min, (_X)->tm_wday, (_X)->tm_hour, (_X)->tm_yday,\
465 (_X)->tm_mday, (_X)->tm_isdst, (_X)->tm_mon)
467#define DEBUG_TMFC(_X)
498#define tmtcTm(_X) (&(_X)->tm)
499#define tmtcTzn(_X) ((_X)->tzn)
500#define tmtcFsec(_X) ((_X)->fsec)
503#define COPY_tm(_DST, _SRC) \
505 (_DST)->tm_sec = (_SRC)->tm_sec; \
506 (_DST)->tm_min = (_SRC)->tm_min; \
507 (_DST)->tm_hour = (_SRC)->tm_hour; \
508 (_DST)->tm_mday = (_SRC)->tm_mday; \
509 (_DST)->tm_mon = (_SRC)->tm_mon; \
510 (_DST)->tm_year = (_SRC)->tm_year; \
511 (_DST)->tm_wday = (_SRC)->tm_wday; \
512 (_DST)->tm_yday = (_SRC)->tm_yday; \
513 (_DST)->tm_gmtoff = (_SRC)->tm_gmtoff; \
519 memset(_X, 0, sizeof(*(_X))); \
520 (_X)->tm_mday = (_X)->tm_mon = 1; \
523#define ZERO_tmtc(_X) \
525 ZERO_tm( tmtcTm(_X) ); \
527 tmtcTzn(_X) = NULL; \
534#define INVALID_FOR_INTERVAL \
538 (errcode(ERRCODE_INVALID_DATETIME_FORMAT), \
539 errmsg("invalid format specification for an interval value"), \
540 errhint("Intervals are not tied to specific calendar dates."))); \
550#define DCH_SUFFIX_FM 0x01
551#define DCH_SUFFIX_TH 0x02
552#define DCH_SUFFIX_th 0x04
553#define DCH_SUFFIX_SP 0x08
554#define DCH_SUFFIX_TM 0x10
599#define TM_SUFFIX_LEN 2
982 -1, -1, -1, -1, -1, -1, -1, -1,
983 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
984 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
985 -1, -1, -1, -1, -1,
DCH_A_D,
DCH_B_C,
DCH_CC,
DCH_DAY, -1,
986 DCH_FF1, -1,
DCH_HH24,
DCH_IDDD,
DCH_J, -1, -1,
DCH_MI, -1,
DCH_OF,
987 DCH_P_M,
DCH_Q,
DCH_RM,
DCH_SSSSS,
DCH_TZH,
DCH_US, -1,
DCH_WW, -1,
DCH_Y_YYY,
988 -1, -1, -1, -1, -1, -1, -1,
DCH_a_d,
DCH_b_c,
DCH_cc,
989 DCH_day, -1,
DCH_ff1, -1,
DCH_hh24,
DCH_iddd,
DCH_j, -1, -1,
DCH_mi,
990 -1,
DCH_of,
DCH_p_m,
DCH_q,
DCH_rm,
DCH_sssss,
DCH_tzh,
DCH_us, -1,
DCH_ww,
1005 -1, -1, -1, -1, -1, -1, -1, -1,
1006 -1, -1, -1, -1,
NUM_COMMA, -1,
NUM_DEC, -1,
NUM_0, -1,
1007 -1, -1, -1, -1, -1, -1, -1,
NUM_9, -1, -1,
1008 -1, -1, -1, -1, -1, -1,
NUM_B,
NUM_C,
NUM_D,
NUM_E,
1009 NUM_FM,
NUM_G, -1, -1, -1, -1,
NUM_L,
NUM_MI, -1, -1,
1010 NUM_PL, -1,
NUM_RN,
NUM_SG,
NUM_TH, -1,
NUM_V, -1, -1, -1,
1011 -1, -1, -1, -1, -1, -1, -1, -1,
NUM_b,
NUM_c,
1012 NUM_d,
NUM_e,
NUM_fm,
NUM_g, -1, -1, -1, -1,
NUM_l,
NUM_mi,
1013 -1, -1,
NUM_pl, -1,
NUM_rn,
NUM_sg,
NUM_th, -1,
NUM_v, -1,
1014 -1, -1, -1, -1, -1, -1
1053#define DCH_DATED 0x01
1054#define DCH_TIMED 0x02
1055#define DCH_ZONED 0x04
1062#define OVERLOAD_TEST (Np->inout_p >= Np->inout + input_len)
1063#define AMOUNT_TEST(s) (Np->inout_p <= Np->inout + (input_len - (s)))
1082#ifdef DEBUG_TO_FROM_CHAR
1103 const char *
const *array,
1162 if (s->type !=
type)
1175 return (*
str > 0x20 && *
str < 0x7F &&
1176 !(*
str >=
'A' && *
str <=
'Z') &&
1177 !(*
str >=
'a' && *
str <=
'z') &&
1178 !(*
str >=
'0' && *
str <=
'9'));
1193 errmsg(
"\"EEEE\" must be the last pattern used")));
1201 errmsg(
"\"9\" must be ahead of \"PR\"")));
1217 errmsg(
"\"0\" must be ahead of \"PR\"")));
1244 errmsg(
"multiple decimal points")));
1248 errmsg(
"cannot use \"V\" and decimal point together")));
1260 errmsg(
"cannot use \"S\" twice")));
1264 errmsg(
"cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together")));
1284 errmsg(
"cannot use \"S\" and \"MI\" together")));
1294 errmsg(
"cannot use \"S\" and \"PL\" together")));
1304 errmsg(
"cannot use \"S\" and \"SG\" together")));
1313 errmsg(
"cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together")));
1322 errmsg(
"cannot use \"RN\" twice")));
1335 errmsg(
"cannot use \"V\" and decimal point together")));
1343 errmsg(
"cannot use \"EEEE\" twice")));
1349 errmsg(
"\"EEEE\" is incompatible with other formats"),
1350 errdetail(
"\"EEEE\" may only be used together with digit and decimal point patterns.")));
1359 errmsg(
"\"RN\" is incompatible with other formats"),
1360 errdetail(
"\"RN\" may only be used together with \"FM\".")));
1375#ifdef DEBUG_TO_FROM_CHAR
1440 errmsg(
"invalid datetime format separator: \"%s\"",
1455 else if (*
str ==
'"')
1469 if (*
str ==
'\\' && *(
str + 1))
1487 if (*
str ==
'\\' && *(
str + 1) ==
'"')
1515#ifdef DEBUG_TO_FROM_CHAR
1517#define DUMP_THth(_suf) (IS_SUFFIX_TH(_suf) ? "TH" : (IS_SUFFIX_th(_suf) ? "th" : " "))
1518#define DUMP_FM(_suf) (IS_SUFFIX_FM(_suf) ? "FM" : " ")
1528 for (
a = 0, n = node;
a <= max; n++,
a++)
1562 last = num[
len - 1];
1563 if (!
isdigit((
unsigned char) last))
1566 errmsg(
"\"%s\" is not a number", num)));
1572 if (
len > 1 && num[
len - 2] ==
'1')
1635 errmsg(
"could not determine which collation to use for %s function",
1637 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1649 const char *src =
buff;
1699 errmsg(
"could not determine which collation to use for %s function",
1701 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1713 const char *src =
buff;
1763 errmsg(
"could not determine which collation to use for %s function",
1765 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1777 const char *src =
buff;
1827 errmsg(
"could not determine which collation to use for %s function",
1829 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1835 errmsg(
"Unicode case folding can only be performed if server encoding is UTF8")));
1846 const char *src =
buff;
1889 for (
char *p = result; *p; p++)
1911 for (
char *p = result; *p; p++)
1934 for (
char *p = result; *p; p++)
1944 (
c >=
'a' &&
c <=
'z') ||
1945 (
c >=
'0' &&
c <=
'9'));
1991#define SKIP_THth(ptr, _suf) \
1993 if (IS_SUFFIX_THth(_suf)) \
1995 if (*(ptr)) (ptr) += pg_mblen(ptr); \
1996 if (*(ptr)) (ptr) += pg_mblen(ptr); \
2001#ifdef DEBUG_TO_FROM_CHAR
2079 else if (year < 100)
2082 else if (year < 520)
2085 else if (year < 1000)
2125 errmsg(
"invalid combination of date conventions"),
2126 errhint(
"Do not mix Gregorian and ISO week date conventions in a formatting template.")));
2144 if (*dest != 0 && *dest !=
value)
2147 errmsg(
"conflicting values for \"%s\" field in formatting string",
2149 errdetail(
"This value contradicts a previous setting for the same field type.")));
2181 const char *
init = *src;
2215 errmsg(
"source string too short for \"%s\" formatting field",
2217 errdetail(
"Field requires %zu characters, but only %zu remain.",
2219 errhint(
"If your source string is not fixed-width, try using the \"FM\" modifier.")));
2225 if (used > 0 && used <
len)
2228 errmsg(
"invalid value \"%s\" for \"%s\"",
2230 errdetail(
"Field requires %zu characters, but only %zu could be parsed.",
2232 errhint(
"If your source string is not fixed-width, try using the \"FM\" modifier.")));
2240 errmsg(
"invalid value \"%s\" for \"%s\"",
2242 errdetail(
"Value must be an integer.")));
2247 errmsg(
"value for \"%s\" in source string is out of range",
2249 errdetail(
"Value must be in the range %d to %d.",
2302 for (
const char *
const *
a = array; *
a !=
NULL;
a++)
2309 for (
const char *p = *
a + 1, *n =
name + 1;; p++, n++)
2357 for (
char **
a = array; *
a !=
NULL;
a++)
2376 for (
char **
a = array; *
a !=
NULL;
a++)
2455 errmsg(
"invalid value \"%s\" for \"%s\"",
2457 errdetail(
"The given value did not match any of the allowed values for this field.")));
2550#define DCH_to_char_fsec(frac_fmt, frac_val) \
2551 sprintf(s, frac_fmt, (int) (frac_val)); \
2552 if (IS_SUFFIX_THth(n->suffix)) \
2553 str_numth(s, s, SUFFIX_TH_TYPE(n->suffix)); \
2576#undef DCH_to_char_fsec
2670 errmsg(
"localized string format value too long")));
2690 errmsg(
"localized string format value too long")));
2710 errmsg(
"localized string format value too long")));
2730 errmsg(
"localized string format value too long")));
2749 errmsg(
"localized string format value too long")));
2768 errmsg(
"localized string format value too long")));
2792 errmsg(
"localized string format value too long")));
2810 errmsg(
"localized string format value too long")));
2828 errmsg(
"localized string format value too long")));
2846 errmsg(
"localized string format value too long")));
2863 errmsg(
"localized string format value too long")));
2880 errmsg(
"localized string format value too long")));
3037 const char *
const *
months;
3138 while (*s !=
'\0' &&
isspace((
unsigned char) *s))
3160 errmsg(
"unmatched format separator \"%c\"",
3221 errmsg(
"unmatched format character \"%s\"",
3291 out->
ms *=
len == 1 ? 100 :
3307 out->
ff, n, escontext);
3311 out->
us *=
len == 1 ? 100000 :
3342 else if (
isalpha((
unsigned char) *s))
3353 errdetail(
"Time zone abbreviation is not recognized.")));
3361 if (*s ==
'+' || *s ==
'-' || *s ==
' ')
3363 out->
tzsign = *s ==
'-' ? -1 : +1;
3392 if (*s ==
'+' || *s ==
'-' || *s ==
' ')
3394 out->
tzsign = *s ==
'-' ? -1 : +1;
3554 errmsg(
"invalid value \"%s\" for \"%s\"", s,
"Y,YYY")));
3561 errmsg(
"value for \"%s\" in source string is out of range",
"Y,YYY")));
3633 while (*s !=
'\0' &&
isspace((
unsigned char) *s))
3650 errmsg(
"input string is too short for datetime format")));
3652 while (*s !=
'\0' &&
isspace((
unsigned char) *s))
3658 errmsg(
"trailing characters remain in input string after datetime format")));
3794#ifdef DEBUG_TO_FROM_CHAR
3811#ifdef DEBUG_TO_FROM_CHAR
3822#ifdef DEBUG_TO_FROM_CHAR
3975 errmsg(
"timestamp out of range")));
4011 errmsg(
"timestamp out of range")));
4096 errmsg(
"timestamp out of range")));
4157 Oid *typid,
int32 *typmod,
int *tz,
4167 &
tm, &fsec, &
ftz, &
fprec, &flags, escontext))
4195 errmsg(
"missing time zone in input string for type timestamptz")));
4201 errmsg(
"timestamptz out of range")));
4215 errmsg(
"timestamp out of range")));
4229 errmsg(
"datetime format is zoned but not timed")));
4263 *tz =
ftz.gmtoffset;
4276 errmsg(
"missing time zone in input string for type timetz")));
4282 errmsg(
"timetz out of range")));
4296 errmsg(
"time out of range")));
4308 errmsg(
"datetime format is not dated and not timed")));
4389 bool incache =
false;
4435#ifdef DEBUG_TO_FROM_CHAR
4478 if (
tmfc.clock_12_hour)
4485 errhint(
"Use the 24-hour clock, or give an hour between 1 and 12.")));
4662 errmsg(
"cannot calculate day of year without year information")));
4680 static const int ysum[2][13] = {
4681 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
4682 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}};
4768 if (
tmfc.tzsign > 0)
4771 else if (
tmfc.has_tz)
4849#ifdef DEBUG_TO_FROM_CHAR
4866#ifdef DEBUG_TO_FROM_CHAR
4877#ifdef DEBUG_TO_FROM_CHAR
4959 memset(Num, 0,
sizeof *Num);
4989#ifdef DEBUG_TO_FROM_CHAR
5020 if (number > 3999 || number < 1)
5030 for (
char *p =
numstr; *p !=
'\0'; p++, --
len)
5032 num = *p - (
'0' + 1);
5106 for (
size_t i = 0;
i <
len;
i++)
5165 if (nextChar ==
'V')
5167 else if (nextChar ==
'L')
5169 else if (nextChar ==
'D')
5215 if (
Np->Num->need_locale)
5227 if (
lconv->negative_sign && *
lconv->negative_sign)
5228 Np->L_negative_sign =
lconv->negative_sign;
5230 Np->L_negative_sign =
"-";
5232 if (
lconv->positive_sign && *
lconv->positive_sign)
5233 Np->L_positive_sign =
lconv->positive_sign;
5235 Np->L_positive_sign =
"+";
5240 if (
lconv->decimal_point && *
lconv->decimal_point)
5241 Np->decimal =
lconv->decimal_point;
5256 if (
lconv->thousands_sep && *
lconv->thousands_sep)
5257 Np->L_thousands_sep =
lconv->thousands_sep;
5259 else if (
strcmp(
Np->decimal,
",") != 0)
5260 Np->L_thousands_sep =
",";
5262 Np->L_thousands_sep =
".";
5267 if (
lconv->currency_symbol && *
lconv->currency_symbol)
5268 Np->L_currency_symbol =
lconv->currency_symbol;
5270 Np->L_currency_symbol =
" ";
5277 Np->L_negative_sign =
"-";
5278 Np->L_positive_sign =
"+";
5281 Np->L_thousands_sep =
",";
5282 Np->L_currency_symbol =
" ";
5299#ifdef DEBUG_TO_FROM_CHAR
5325#ifdef DEBUG_TO_FROM_CHAR
5333 if (*
Np->inout_p ==
' ')
5342 if (*
Np->number ==
' ' && (
id ==
NUM_0 ||
id ==
NUM_9) &&
5343 (
Np->read_pre +
Np->read_post) == 0)
5345#ifdef DEBUG_TO_FROM_CHAR
5347 *
Np->inout_p,
Np->L_positive_sign,
Np->L_negative_sign);
5357#ifdef DEBUG_TO_FROM_CHAR
5360 if ((
x =
strlen(
Np->L_negative_sign)) &&
5367 else if ((
x =
strlen(
Np->L_positive_sign)) &&
5377#ifdef DEBUG_TO_FROM_CHAR
5385 *
Np->inout_p ==
'<'))
5390 else if (*
Np->inout_p ==
'+')
5401#ifdef DEBUG_TO_FROM_CHAR
5408 if (
isdigit((
unsigned char) *
Np->inout_p))
5410 if (
Np->read_dec &&
Np->read_post ==
Np->Num->post)
5413 *
Np->number_p = *
Np->inout_p;
5423#ifdef DEBUG_TO_FROM_CHAR
5436#ifdef DEBUG_TO_FROM_CHAR
5442 Np->inout_p +=
x - 1;
5443 *
Np->number_p =
'.';
5445 Np->read_dec =
true;
5462 if (*
Np->number ==
' ' &&
Np->read_pre +
Np->read_post > 0)
5470 (
Np->inout_p + 1) <
Np->inout + input_len &&
5471 !
isdigit((
unsigned char) *(
Np->inout_p + 1)))
5474 char *tmp =
Np->inout_p++;
5476#ifdef DEBUG_TO_FROM_CHAR
5479 if ((
x =
strlen(
Np->L_negative_sign)) &&
5483 Np->inout_p +=
x - 1;
5486 else if ((
x =
strlen(
Np->L_positive_sign)) &&
5490 Np->inout_p +=
x - 1;
5493 if (*
Np->number ==
' ')
5511#ifdef DEBUG_TO_FROM_CHAR
5518 if (*
Np->inout_p ==
'-' || *
Np->inout_p ==
'+')
5520 *
Np->number = *
Np->inout_p;
5525#define IS_PREDEC_SPACE(_n) \
5526 (IS_ZERO((_n)->Num)==false && \
5527 (_n)->number == (_n)->number_p && \
5528 *(_n)->number == '0' && \
5529 (_n)->Num->post != 0)
5544#ifdef DEBUG_TO_FROM_CHAR
5551 "SIGN_WROTE: %d, CURRENT: %d, NUMBER_P: \"%s\", INOUT: \"%s\"",
5563 if (
Np->sign_wrote ==
false &&
5564 (
Np->num_curr >=
Np->out_pre_spaces || (
IS_ZERO(
Np->Num) &&
Np->Num->zero_start ==
Np->num_curr)) &&
5571 if (
Np->sign ==
'-')
5576 Np->sign_wrote =
true;
5581 *
Np->inout_p =
Np->sign ==
'+' ?
' ' :
'<';
5583 Np->sign_wrote =
true;
5585 else if (
Np->sign ==
'+')
5592 Np->sign_wrote =
true;
5594 else if (
Np->sign ==
'-')
5598 Np->sign_wrote =
true;
5608 if (
Np->num_curr <
Np->out_pre_spaces &&
5621 Np->num_curr <
Np->out_pre_spaces &&
5622 Np->Num->zero_start <=
Np->num_curr)
5636 if (*
Np->number_p ==
'.')
5638 if (!
Np->last_relevant || *
Np->last_relevant !=
'.')
5648 Np->last_relevant && *
Np->last_relevant ==
'.')
5659 if (
Np->last_relevant &&
Np->number_p >
Np->last_relevant &&
5677 else if (
Np->last_relevant && *
Np->last_relevant ==
'.')
5685 *
Np->inout_p = *
Np->number_p;
5695 end =
Np->num_count + (
Np->out_pre_spaces ? 1 : 0) + (
IS_DECIMAL(
Np->Num) ? 1 : 0);
5697 if (
Np->last_relevant &&
Np->last_relevant ==
Np->number_p)
5700 if (
Np->num_curr + 1 == end)
5704 *
Np->inout_p =
Np->sign ==
'+' ?
' ' :
'>';
5709 if (
Np->sign ==
'-')
5745 const char *pattern;
5751 Np->is_to_char = is_to_char;
5752 Np->number = number;
5754 Np->last_relevant =
NULL;
5757 Np->read_dec =
false;
5759 if (
Np->Num->zero_start)
5764 if (!
Np->is_to_char)
5767 errmsg(
"\"EEEE\" not supported for input")));
5768 return strcpy(inout, number);
5782 Np->sign_wrote =
false;
5784 Np->sign_wrote =
true;
5788 if (
Np->sign !=
'-')
5795 Np->sign_wrote =
true;
5797 Np->sign_wrote =
false;
5809 Np->num_count =
Np->Num->post +
Np->Num->pre - 1;
5825 if (
Np->last_relevant &&
Np->Num->zero_end >
Np->out_pre_spaces)
5833 Np->Num->zero_end -
Np->out_pre_spaces);
5840 if (
Np->sign_wrote ==
false &&
Np->out_pre_spaces == 0)
5845 Np->out_pre_spaces = 0;
5847 *(
Np->number + 1) =
'\0';
5853#ifdef DEBUG_TO_FROM_CHAR
5855 "\n\tSIGN: '%c'\n\tNUM: '%s'\n\tPRE: %d\n\tPOST: %d\n\tNUM_COUNT: %d\n\tNUM_PRE: %d\n\tSIGN_WROTE: %s\n\tZERO: %s\n\tZERO_START: %d\n\tZERO_END: %d\n\tLAST_RELEVANT: %s\n\tBRACKET: %s\n\tPLUS: %s\n\tMINUS: %s\n\tFILLMODE: %s\n\tROMAN: %s\n\tEEEE: %s",
5862 Np->sign_wrote ?
"Yes" :
"No",
5864 Np->Num->zero_start,
5866 Np->last_relevant ?
Np->last_relevant :
"<not set>",
5885 Np->number_p =
Np->number;
5887 Np->number_p =
Np->number + 1;
5891 if (!
Np->is_to_char)
5956 if (*
Np->inout_p !=
',')
5962 pattern =
Np->L_thousands_sep;
6007 pattern =
Np->L_currency_symbol;
6011 Np->inout_p +=
strlen(pattern) - 1;
6024 const char *number_p;
6029 number_p =
Np->number_p;
6044 errmsg(
"invalid Roman numeral")));
6092 if (
Np->sign ==
'-')
6101 if (*
Np->inout_p ==
'-')
6114 if (
Np->sign ==
'+')
6123 if (*
Np->inout_p ==
'+')
6135 *
Np->inout_p =
Np->sign;
6138 if (*
Np->inout_p ==
'-')
6140 else if (*
Np->inout_p ==
'+')
6179 *
Np->inout_p =
'\0';
6184 if (*(
Np->number_p - 1) ==
'.')
6185 *(
Np->number_p - 1) =
'\0';
6187 *
Np->number_p =
'\0';
6192 Np->Num->post =
Np->read_post;
6194#ifdef DEBUG_TO_FROM_CHAR
6205#define NUM_TOCHAR_prepare \
6207 int len = VARSIZE_ANY_EXHDR(fmt); \
6208 if (len <= 0 || len >= (INT_MAX-VARHDRSZ)/NUM_MAX_ITEM_SIZ) \
6209 PG_RETURN_TEXT_P(cstring_to_text("")); \
6210 result = (text *) palloc0((len * NUM_MAX_ITEM_SIZ) + 1 + VARHDRSZ); \
6211 format = NUM_cache(len, &Num, fmt, &shouldFree); \
6217#define NUM_TOCHAR_finish \
6221 NUM_processor(format, &Num, VARDATA(result), numstr, 0, out_pre_spaces, sign, true, PG_GET_COLLATION()); \
6231 len = strlen(VARDATA(result)); \
6232 SET_VARSIZE(result, len + VARHDRSZ); \
6305 int out_pre_spaces = 0,
6432 int out_pre_spaces = 0,
6525 int out_pre_spaces = 0,
6574 double multi =
pow((
double) 10, (
double) Num.
multi);
6636 int out_pre_spaces = 0,
6688 float multi =
pow((
double) 10, (
double) Num.
multi);
6748 int out_pre_spaces = 0,
6800 double multi =
pow((
double) 10, (
double) Num.
multi);
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
void DateTimeParseError(int dterr, DateTimeErrorExtra *extra, const char *str, const char *datatype, Node *escontext)
int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc, struct pg_tm *tm)
void j2date(int jd, int *year, int *month, int *day)
const char *const months[]
int date2j(int year, int month, int day)
int DecodeTimezoneAbbrevPrefix(const char *str, int *offset, pg_tz **tz)
int DetermineTimeZoneAbbrevOffset(struct pg_tm *tm, const char *abbr, pg_tz *tzp)
char * numeric_out_sci(Numeric num, int scale)
Datum numeric_round(PG_FUNCTION_ARGS)
Numeric int64_to_numeric(int64 val)
int32 numeric_int4_safe(Numeric num, Node *escontext)
Datum numeric_power(PG_FUNCTION_ARGS)
Datum numeric_out(PG_FUNCTION_ARGS)
Datum numeric_in(PG_FUNCTION_ARGS)
Datum numeric_mul(PG_FUNCTION_ARGS)
void isoweek2date(int woy, int *year, int *mon, int *mday)
int isoweek2j(int year, int week)
int date2isoweek(int year, int mon, int mday)
bool AdjustTimestampForTypmod(Timestamp *time, int32 typmod, Node *escontext)
int date2isoyearday(int year, int mon, int mday)
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
void isoweekdate2date(int isoweek, int wday, int *year, int *mon, int *mday)
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
void interval2itm(Interval span, struct pg_itm *itm)
int date2isoyear(int year, int mon, int mday)
#define FLOAT4_FITS_IN_INT32(num)
#define FLOAT8_FITS_IN_INT32(num)
#define Assert(condition)
#define MemSet(start, val, len)
#define OidIsValid(objectId)
#define INTERVAL_NOT_FINITE(i)
#define IS_VALID_JULIAN(y, m, d)
#define TIMESTAMP_NOT_FINITE(j)
#define POSTGRES_EPOCH_JDATE
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
static Datum DateADTGetDatum(DateADT X)
#define PG_RETURN_DATEADT(x)
static Datum TimeTzADTPGetDatum(const TimeTzADT *X)
static Datum TimeADTGetDatum(TimeADT X)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define errsave(context,...)
#define ereport(elevel,...)
#define palloc_object(type)
#define PG_GETARG_TEXT_PP(n)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_FLOAT8(n)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_INT64(n)
#define PG_RETURN_TEXT_P(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_FLOAT4(n)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_GET_COLLATION()
#define DTERR_TZDISP_OVERFLOW
#define DTERR_FIELD_OVERFLOW
Datum int8out(PG_FUNCTION_ARGS)
Datum int8mul(PG_FUNCTION_ARGS)
Datum dtoi8(PG_FUNCTION_ARGS)
Datum int4out(PG_FUNCTION_ARGS)
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
int GetDatabaseEncoding(void)
int pg_mbstrlen(const char *mbstr)
int pg_mblen(const char *mbstr)
void * MemoryContextAllocZero(MemoryContext context, Size size)
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
MemoryContext TopMemoryContext
char * pnstrdup(const char *in, Size len)
#define SOFT_ERROR_OCCURRED(escontext)
static Numeric DatumGetNumeric(Datum X)
#define PG_GETARG_NUMERIC(n)
static Datum NumericGetDatum(Numeric X)
static PgChecksumMode mode
void cache_locale_time(void)
char * localized_full_months[12+1]
pg_locale_t pg_newlocale_from_collation(Oid collid)
size_t pg_strfold(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t pg_strlower(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
struct lconv * PGLC_localeconv(void)
size_t pg_strtitle(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
char * localized_abbrev_months[12+1]
char * localized_full_days[7+1]
size_t pg_strupper(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
char * localized_abbrev_days[7+1]
#define MAX_MULTIBYTE_CHAR_LEN
PGDLLIMPORT pg_tz * session_timezone
static unsigned char pg_ascii_tolower(unsigned char ch)
static unsigned char pg_ascii_toupper(unsigned char ch)
size_t strlcpy(char *dst, const char *src, size_t siz)
static Datum Int64GetDatum(int64 X)
static int64 DatumGetInt64(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum X)
static Datum Float8GetDatum(float8 X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
char * psprintf(const char *fmt,...)
bool scanner_isspace(char ch)
FromCharDateMode date_mode
const char * L_thousands_sep
const char * L_negative_sign
const char * L_currency_symbol
const char * last_relevant
const char * L_positive_sign
static Datum TimestampTzGetDatum(TimestampTz X)
static Datum TimestampGetDatum(Timestamp X)
#define PG_GETARG_TIMESTAMP(n)
#define PG_RETURN_TIMESTAMP(x)
#define PG_GETARG_INTERVAL_P(n)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
text * cstring_to_text(const char *s)
char * text_to_cstring(const text *t)