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,
1163 if (s->type !=
type)
1176 return (*
str > 0x20 && *
str < 0x7F &&
1177 !(*
str >=
'A' && *
str <=
'Z') &&
1178 !(*
str >=
'a' && *
str <=
'z') &&
1179 !(*
str >=
'0' && *
str <=
'9'));
1194 errmsg(
"\"EEEE\" must be the last pattern used")));
1202 errmsg(
"\"9\" must be ahead of \"PR\"")));
1218 errmsg(
"\"0\" must be ahead of \"PR\"")));
1245 errmsg(
"multiple decimal points")));
1249 errmsg(
"cannot use \"V\" and decimal point together")));
1261 errmsg(
"cannot use \"S\" twice")));
1265 errmsg(
"cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together")));
1285 errmsg(
"cannot use \"S\" and \"MI\" together")));
1295 errmsg(
"cannot use \"S\" and \"PL\" together")));
1305 errmsg(
"cannot use \"S\" and \"SG\" together")));
1314 errmsg(
"cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together")));
1323 errmsg(
"cannot use \"RN\" twice")));
1336 errmsg(
"cannot use \"V\" and decimal point together")));
1344 errmsg(
"cannot use \"EEEE\" twice")));
1350 errmsg(
"\"EEEE\" is incompatible with other formats"),
1351 errdetail(
"\"EEEE\" may only be used together with digit and decimal point patterns.")));
1360 errmsg(
"\"RN\" is incompatible with other formats"),
1361 errdetail(
"\"RN\" may only be used together with \"FM\".")));
1376#ifdef DEBUG_TO_FROM_CHAR
1441 errmsg(
"invalid datetime format separator: \"%s\"",
1456 else if (*
str ==
'"')
1470 if (*
str ==
'\\' && *(
str + 1))
1488 if (*
str ==
'\\' && *(
str + 1) ==
'"')
1516#ifdef DEBUG_TO_FROM_CHAR
1518#define DUMP_THth(_suf) (IS_SUFFIX_TH(_suf) ? "TH" : (IS_SUFFIX_th(_suf) ? "th" : " "))
1519#define DUMP_FM(_suf) (IS_SUFFIX_FM(_suf) ? "FM" : " ")
1529 for (
a = 0, n = node;
a <= max; n++,
a++)
1563 last = num[
len - 1];
1564 if (!
isdigit((
unsigned char) last))
1567 errmsg(
"\"%s\" is not a number", num)));
1573 if (
len > 1 && num[
len - 2] ==
'1')
1636 errmsg(
"could not determine which collation to use for %s function",
1638 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1650 const char *src =
buff;
1700 errmsg(
"could not determine which collation to use for %s function",
1702 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1714 const char *src =
buff;
1764 errmsg(
"could not determine which collation to use for %s function",
1766 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1778 const char *src =
buff;
1828 errmsg(
"could not determine which collation to use for %s function",
1830 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1836 errmsg(
"Unicode case folding can only be performed if server encoding is UTF8")));
1847 const char *src =
buff;
1890 for (
char *p =
result; *p; p++)
1912 for (
char *p =
result; *p; p++)
1935 for (
char *p =
result; *p; p++)
1945 (
c >=
'a' &&
c <=
'z') ||
1946 (
c >=
'0' &&
c <=
'9'));
1992#define SKIP_THth(ptr, _suf) \
1994 if (IS_SUFFIX_THth(_suf)) \
1996 if (*(ptr)) (ptr) += pg_mblen_cstr(ptr); \
1997 if (*(ptr)) (ptr) += pg_mblen_cstr(ptr); \
2002#ifdef DEBUG_TO_FROM_CHAR
2080 else if (year < 100)
2083 else if (year < 520)
2086 else if (year < 1000)
2126 errmsg(
"invalid combination of date conventions"),
2127 errhint(
"Do not mix Gregorian and ISO week date conventions in a formatting template.")));
2145 if (*dest != 0 && *dest !=
value)
2148 errmsg(
"conflicting values for \"%s\" field in formatting string",
2150 errdetail(
"This value contradicts a previous setting for the same field type.")));
2182 const char *
init = *src;
2216 errmsg(
"source string too short for \"%s\" formatting field",
2218 errdetail(
"Field requires %zu characters, but only %zu remain.",
2220 errhint(
"If your source string is not fixed-width, try using the \"FM\" modifier.")));
2226 if (used > 0 && used <
len)
2229 errmsg(
"invalid value \"%s\" for \"%s\"",
2231 errdetail(
"Field requires %zu characters, but only %zu could be parsed.",
2233 errhint(
"If your source string is not fixed-width, try using the \"FM\" modifier.")));
2241 errmsg(
"invalid value \"%s\" for \"%s\"",
2243 errdetail(
"Value must be an integer.")));
2248 errmsg(
"value for \"%s\" in source string is out of range",
2250 errdetail(
"Value must be in the range %d to %d.",
2303 for (
const char *
const *
a = array; *
a !=
NULL;
a++)
2310 for (
const char *p = *
a + 1, *n =
name + 1;; p++, n++)
2358 for (
char **
a = array; *
a !=
NULL;
a++)
2377 for (
char **
a = array; *
a !=
NULL;
a++)
2456 errmsg(
"invalid value \"%s\" for \"%s\"",
2458 errdetail(
"The given value did not match any of the allowed values for this field.")));
2551#define DCH_to_char_fsec(frac_fmt, frac_val) \
2552 sprintf(s, frac_fmt, (int) (frac_val)); \
2553 if (IS_SUFFIX_THth(n->suffix)) \
2554 str_numth(s, s, SUFFIX_TH_TYPE(n->suffix)); \
2577#undef DCH_to_char_fsec
2671 errmsg(
"localized string format value too long")));
2691 errmsg(
"localized string format value too long")));
2711 errmsg(
"localized string format value too long")));
2731 errmsg(
"localized string format value too long")));
2750 errmsg(
"localized string format value too long")));
2769 errmsg(
"localized string format value too long")));
2793 errmsg(
"localized string format value too long")));
2811 errmsg(
"localized string format value too long")));
2829 errmsg(
"localized string format value too long")));
2847 errmsg(
"localized string format value too long")));
2864 errmsg(
"localized string format value too long")));
2881 errmsg(
"localized string format value too long")));
3038 const char *
const *
months;
3139 while (*s !=
'\0' &&
isspace((
unsigned char) *s))
3161 errmsg(
"unmatched format separator \"%c\"",
3222 errmsg(
"unmatched format character \"%s\"",
3292 out->
ms *=
len == 1 ? 100 :
3308 out->
ff, n, escontext);
3312 out->
us *=
len == 1 ? 100000 :
3343 else if (
isalpha((
unsigned char) *s))
3354 errdetail(
"Time zone abbreviation is not recognized.")));
3362 if (*s ==
'+' || *s ==
'-' || *s ==
' ')
3364 out->
tzsign = *s ==
'-' ? -1 : +1;
3393 if (*s ==
'+' || *s ==
'-' || *s ==
' ')
3395 out->
tzsign = *s ==
'-' ? -1 : +1;
3555 errmsg(
"invalid value \"%s\" for \"%s\"", s,
"Y,YYY")));
3562 errmsg(
"value for \"%s\" in source string is out of range",
"Y,YYY")));
3634 while (*s !=
'\0' &&
isspace((
unsigned char) *s))
3651 errmsg(
"input string is too short for datetime format")));
3653 while (*s !=
'\0' &&
isspace((
unsigned char) *s))
3659 errmsg(
"trailing characters remain in input string after datetime format")));
3795#ifdef DEBUG_TO_FROM_CHAR
3812#ifdef DEBUG_TO_FROM_CHAR
3823#ifdef DEBUG_TO_FROM_CHAR
3976 errmsg(
"timestamp out of range")));
4012 errmsg(
"timestamp out of range")));
4097 errmsg(
"timestamp out of range")));
4158 Oid *typid,
int32 *typmod,
int *tz,
4168 &
tm, &fsec, &
ftz, &
fprec, &flags, escontext))
4196 errmsg(
"missing time zone in input string for type timestamptz")));
4202 errmsg(
"timestamptz out of range")));
4216 errmsg(
"timestamp out of range")));
4230 errmsg(
"datetime format is zoned but not timed")));
4264 *tz =
ftz.gmtoffset;
4277 errmsg(
"missing time zone in input string for type timetz")));
4283 errmsg(
"timetz out of range")));
4297 errmsg(
"time out of range")));
4309 errmsg(
"datetime format is not dated and not timed")));
4390 bool incache =
false;
4436#ifdef DEBUG_TO_FROM_CHAR
4479 if (
tmfc.clock_12_hour)
4486 errhint(
"Use the 24-hour clock, or give an hour between 1 and 12.")));
4663 errmsg(
"cannot calculate day of year without year information")));
4681 static const int ysum[2][13] = {
4682 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
4683 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}};
4769 if (
tmfc.tzsign > 0)
4772 else if (
tmfc.has_tz)
4850#ifdef DEBUG_TO_FROM_CHAR
4867#ifdef DEBUG_TO_FROM_CHAR
4878#ifdef DEBUG_TO_FROM_CHAR
4960 memset(Num, 0,
sizeof *Num);
4990#ifdef DEBUG_TO_FROM_CHAR
5021 if (number > 3999 || number < 1)
5031 for (
char *p =
numstr; *p !=
'\0'; p++, --
len)
5033 num = *p - (
'0' + 1);
5107 for (
size_t i = 0;
i <
len;
i++)
5166 if (nextChar ==
'V')
5168 else if (nextChar ==
'L')
5170 else if (nextChar ==
'D')
5216 if (
Np->Num->need_locale)
5228 if (
lconv->negative_sign && *
lconv->negative_sign)
5229 Np->L_negative_sign =
lconv->negative_sign;
5231 Np->L_negative_sign =
"-";
5233 if (
lconv->positive_sign && *
lconv->positive_sign)
5234 Np->L_positive_sign =
lconv->positive_sign;
5236 Np->L_positive_sign =
"+";
5241 if (
lconv->decimal_point && *
lconv->decimal_point)
5242 Np->decimal =
lconv->decimal_point;
5257 if (
lconv->thousands_sep && *
lconv->thousands_sep)
5258 Np->L_thousands_sep =
lconv->thousands_sep;
5260 else if (
strcmp(
Np->decimal,
",") != 0)
5261 Np->L_thousands_sep =
",";
5263 Np->L_thousands_sep =
".";
5268 if (
lconv->currency_symbol && *
lconv->currency_symbol)
5269 Np->L_currency_symbol =
lconv->currency_symbol;
5271 Np->L_currency_symbol =
" ";
5278 Np->L_negative_sign =
"-";
5279 Np->L_positive_sign =
"+";
5282 Np->L_thousands_sep =
",";
5283 Np->L_currency_symbol =
" ";
5300#ifdef DEBUG_TO_FROM_CHAR
5326#ifdef DEBUG_TO_FROM_CHAR
5334 if (*
Np->inout_p ==
' ')
5343 if (*
Np->number ==
' ' && (
id ==
NUM_0 ||
id ==
NUM_9) &&
5344 (
Np->read_pre +
Np->read_post) == 0)
5346#ifdef DEBUG_TO_FROM_CHAR
5348 *
Np->inout_p,
Np->L_positive_sign,
Np->L_negative_sign);
5358#ifdef DEBUG_TO_FROM_CHAR
5361 if ((
x =
strlen(
Np->L_negative_sign)) &&
5368 else if ((
x =
strlen(
Np->L_positive_sign)) &&
5378#ifdef DEBUG_TO_FROM_CHAR
5386 *
Np->inout_p ==
'<'))
5391 else if (*
Np->inout_p ==
'+')
5402#ifdef DEBUG_TO_FROM_CHAR
5409 if (
isdigit((
unsigned char) *
Np->inout_p))
5411 if (
Np->read_dec &&
Np->read_post ==
Np->Num->post)
5414 *
Np->number_p = *
Np->inout_p;
5424#ifdef DEBUG_TO_FROM_CHAR
5437#ifdef DEBUG_TO_FROM_CHAR
5443 Np->inout_p +=
x - 1;
5444 *
Np->number_p =
'.';
5446 Np->read_dec =
true;
5463 if (*
Np->number ==
' ' &&
Np->read_pre +
Np->read_post > 0)
5471 (
Np->inout_p + 1) <
Np->inout + input_len &&
5472 !
isdigit((
unsigned char) *(
Np->inout_p + 1)))
5475 char *tmp =
Np->inout_p++;
5477#ifdef DEBUG_TO_FROM_CHAR
5480 if ((
x =
strlen(
Np->L_negative_sign)) &&
5484 Np->inout_p +=
x - 1;
5487 else if ((
x =
strlen(
Np->L_positive_sign)) &&
5491 Np->inout_p +=
x - 1;
5494 if (*
Np->number ==
' ')
5512#ifdef DEBUG_TO_FROM_CHAR
5519 if (*
Np->inout_p ==
'-' || *
Np->inout_p ==
'+')
5521 *
Np->number = *
Np->inout_p;
5526#define IS_PREDEC_SPACE(_n) \
5527 (IS_ZERO((_n)->Num)==false && \
5528 (_n)->number == (_n)->number_p && \
5529 *(_n)->number == '0' && \
5530 (_n)->Num->post != 0)
5545#ifdef DEBUG_TO_FROM_CHAR
5552 "SIGN_WROTE: %d, CURRENT: %d, NUMBER_P: \"%s\", INOUT: \"%s\"",
5564 if (
Np->sign_wrote ==
false &&
5565 (
Np->num_curr >=
Np->out_pre_spaces || (
IS_ZERO(
Np->Num) &&
Np->Num->zero_start ==
Np->num_curr)) &&
5573 Np->L_negative_sign :
5574 Np->L_positive_sign);
5575 Np->sign_wrote =
true;
5580 *
Np->inout_p =
Np->sign ==
'+' ?
' ' :
'<';
5582 Np->sign_wrote =
true;
5584 else if (
Np->sign ==
'+')
5591 Np->sign_wrote =
true;
5593 else if (
Np->sign ==
'-')
5597 Np->sign_wrote =
true;
5607 if (
Np->num_curr <
Np->out_pre_spaces &&
5620 Np->num_curr <
Np->out_pre_spaces &&
5621 Np->Num->zero_start <=
Np->num_curr)
5635 if (*
Np->number_p ==
'.')
5637 if (!
Np->last_relevant || *
Np->last_relevant !=
'.')
5646 Np->last_relevant && *
Np->last_relevant ==
'.')
5656 if (
Np->last_relevant &&
Np->number_p >
Np->last_relevant &&
5674 else if (
Np->last_relevant && *
Np->last_relevant ==
'.')
5682 *
Np->inout_p = *
Np->number_p;
5692 end =
Np->num_count + (
Np->out_pre_spaces ? 1 : 0) + (
IS_DECIMAL(
Np->Num) ? 1 : 0);
5694 if (
Np->last_relevant &&
Np->last_relevant ==
Np->number_p)
5697 if (
Np->num_curr + 1 == end)
5701 *
Np->inout_p =
Np->sign ==
'+' ?
' ' :
'>';
5707 Np->L_negative_sign :
5708 Np->L_positive_sign);
5739 const char *end =
Np->inout + input_len;
5759 const char *pattern;
5765 Np->is_to_char = is_to_char;
5766 Np->number = number;
5768 Np->last_relevant =
NULL;
5771 Np->read_dec =
false;
5773 if (
Np->Num->zero_start)
5778 if (!
Np->is_to_char)
5781 errmsg(
"\"EEEE\" not supported for input")));
5782 return strcpy(inout, number);
5796 Np->sign_wrote =
false;
5798 Np->sign_wrote =
true;
5802 if (
Np->sign !=
'-')
5809 Np->sign_wrote =
true;
5811 Np->sign_wrote =
false;
5823 Np->num_count =
Np->Num->post +
Np->Num->pre - 1;
5839 if (
Np->last_relevant &&
Np->Num->zero_end >
Np->out_pre_spaces)
5847 Np->Num->zero_end -
Np->out_pre_spaces);
5854 if (
Np->sign_wrote ==
false &&
Np->out_pre_spaces == 0)
5859 Np->out_pre_spaces = 0;
5861 *(
Np->number + 1) =
'\0';
5867#ifdef DEBUG_TO_FROM_CHAR
5869 "\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",
5876 Np->sign_wrote ?
"Yes" :
"No",
5878 Np->Num->zero_start,
5880 Np->last_relevant ?
Np->last_relevant :
"<not set>",
5899 Np->number_p =
Np->number;
5901 Np->number_p =
Np->number + 1;
5905 if (!
Np->is_to_char)
5970 if (*
Np->inout_p !=
',')
5976 pattern =
Np->L_thousands_sep;
6027 pattern =
Np->L_currency_symbol;
6051 const char *number_p;
6056 number_p =
Np->number_p;
6071 errmsg(
"invalid Roman numeral")));
6119 if (
Np->sign ==
'-')
6128 if (*
Np->inout_p ==
'-')
6141 if (
Np->sign ==
'+')
6150 if (*
Np->inout_p ==
'+')
6162 *
Np->inout_p =
Np->sign;
6165 if (*
Np->inout_p ==
'-')
6167 else if (*
Np->inout_p ==
'+')
6206 *
Np->inout_p =
'\0';
6211 if (*(
Np->number_p - 1) ==
'.')
6212 *(
Np->number_p - 1) =
'\0';
6214 *
Np->number_p =
'\0';
6219 Np->Num->post =
Np->read_post;
6221#ifdef DEBUG_TO_FROM_CHAR
6232#define NUM_TOCHAR_prepare \
6234 int len = VARSIZE_ANY_EXHDR(fmt); \
6235 if (len <= 0 || len >= (INT_MAX-VARHDRSZ)/NUM_MAX_ITEM_SIZ) \
6236 PG_RETURN_TEXT_P(cstring_to_text("")); \
6237 result = (text *) palloc0((len * NUM_MAX_ITEM_SIZ) + 1 + VARHDRSZ); \
6238 format = NUM_cache(len, &Num, fmt, &shouldFree); \
6244#define NUM_TOCHAR_finish \
6248 NUM_processor(format, &Num, VARDATA(result), numstr, 0, out_pre_spaces, sign, true, PG_GET_COLLATION()); \
6258 len = strlen(VARDATA(result)); \
6259 SET_VARSIZE(result, len + VARHDRSZ); \
6332 int out_pre_spaces = 0,
6459 int out_pre_spaces = 0,
6552 int out_pre_spaces = 0,
6601 double multi =
pow((
double) 10, (
double) Num.
multi);
6663 int out_pre_spaces = 0,
6715 float multi =
pow((
double) 10, (
double) Num.
multi);
6775 int out_pre_spaces = 0,
6827 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)
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#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 errcode(int sqlerrcode)
#define ereturn(context, dummy_value,...)
#define errsave(context,...)
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#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_mblen_cstr(const char *mbstr)
int pg_mbstrlen_with_len(const char *mbstr, int limit)
int pg_mblen_range(const char *mbstr, const char *end)
int pg_mbstrlen(const char *mbstr)
int pg_mbcliplen(const char *mbstr, int len, int limit)
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)