61 #ifdef DEBUG_TO_FROM_CHAR
62 #define DEBUG_elog_output DEBUG3
75 #include <unicode/ustring.h>
107 #define KeyWord_INDEX_SIZE ('~' - ' ')
108 #define KeyWord_INDEX_FILTER(_c) ((_c) <= ' ' || (_c) >= '~' ? 0 : 1)
114 #define DCH_MAX_ITEM_SIZ 12
115 #define NUM_MAX_ITEM_SIZ 8
161 #define NODE_TYPE_END 1
162 #define NODE_TYPE_ACTION 2
163 #define NODE_TYPE_CHAR 3
164 #define NODE_TYPE_SEPARATOR 4
165 #define NODE_TYPE_SPACE 5
167 #define SUFFTYPE_PREFIX 1
168 #define SUFFTYPE_POSTFIX 2
170 #define CLOCK_24_HOUR 0
171 #define CLOCK_12_HOUR 1
179 "January",
"February",
"March",
"April",
"May",
"June",
"July",
180 "August",
"September",
"October",
"November",
"December", NULL
184 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat", NULL
194 #define ADJUST_YEAR(year, is_interval) ((is_interval) ? (year) : ((year) <= 0 ? -((year) - 1) : (year)))
196 #define A_D_STR "A.D."
197 #define a_d_STR "a.d."
201 #define B_C_STR "B.C."
202 #define b_c_STR "b.c."
223 #define A_M_STR "A.M."
224 #define a_m_STR "a.m."
228 #define P_M_STR "P.M."
229 #define p_m_STR "p.m."
253 {
"XII",
"XI",
"X",
"IX",
"VIII",
"VII",
"VI",
"V",
"IV",
"III",
"II",
"I", NULL};
256 {
"xii",
"xi",
"x",
"ix",
"viii",
"vii",
"vi",
"v",
"iv",
"iii",
"ii",
"i", NULL};
262 static const char *
const rm1[] = {
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX", NULL};
263 static const char *
const rm10[] = {
"X",
"XX",
"XXX",
"XL",
"L",
"LX",
"LXX",
"LXXX",
"XC", NULL};
264 static const char *
const rm100[] = {
"C",
"CC",
"CCC",
"CD",
"D",
"DC",
"DCC",
"DCCC",
"CM", NULL};
270 static const char *
const numTH[] = {
"ST",
"ND",
"RD",
"TH", NULL};
271 static const char *
const numth[] = {
"st",
"nd",
"rd",
"th", NULL};
301 #define NUM_F_DECIMAL (1 << 1)
302 #define NUM_F_LDECIMAL (1 << 2)
303 #define NUM_F_ZERO (1 << 3)
304 #define NUM_F_BLANK (1 << 4)
305 #define NUM_F_FILLMODE (1 << 5)
306 #define NUM_F_LSIGN (1 << 6)
307 #define NUM_F_BRACKET (1 << 7)
308 #define NUM_F_MINUS (1 << 8)
309 #define NUM_F_PLUS (1 << 9)
310 #define NUM_F_ROMAN (1 << 10)
311 #define NUM_F_MULTI (1 << 11)
312 #define NUM_F_PLUS_POST (1 << 12)
313 #define NUM_F_MINUS_POST (1 << 13)
314 #define NUM_F_EEEE (1 << 14)
316 #define NUM_LSIGN_PRE (-1)
317 #define NUM_LSIGN_POST 1
318 #define NUM_LSIGN_NONE 0
324 #define IS_DECIMAL(_f) ((_f)->flag & NUM_F_DECIMAL)
325 #define IS_LDECIMAL(_f) ((_f)->flag & NUM_F_LDECIMAL)
326 #define IS_ZERO(_f) ((_f)->flag & NUM_F_ZERO)
327 #define IS_BLANK(_f) ((_f)->flag & NUM_F_BLANK)
328 #define IS_FILLMODE(_f) ((_f)->flag & NUM_F_FILLMODE)
329 #define IS_BRACKET(_f) ((_f)->flag & NUM_F_BRACKET)
330 #define IS_MINUS(_f) ((_f)->flag & NUM_F_MINUS)
331 #define IS_LSIGN(_f) ((_f)->flag & NUM_F_LSIGN)
332 #define IS_PLUS(_f) ((_f)->flag & NUM_F_PLUS)
333 #define IS_ROMAN(_f) ((_f)->flag & NUM_F_ROMAN)
334 #define IS_MULTI(_f) ((_f)->flag & NUM_F_MULTI)
335 #define IS_EEEE(_f) ((_f)->flag & NUM_F_EEEE)
355 #define DCH_CACHE_OVERHEAD \
356 MAXALIGN(sizeof(bool) + sizeof(int))
357 #define NUM_CACHE_OVERHEAD \
358 MAXALIGN(sizeof(bool) + sizeof(int) + sizeof(NUMDesc))
360 #define DCH_CACHE_SIZE \
361 ((2048 - DCH_CACHE_OVERHEAD) / (sizeof(FormatNode) + sizeof(char)) - 1)
362 #define NUM_CACHE_SIZE \
363 ((1024 - NUM_CACHE_OVERHEAD) / (sizeof(FormatNode) + sizeof(char)) - 1)
365 #define DCH_CACHE_ENTRIES 20
366 #define NUM_CACHE_ENTRIES 20
432 #define ZERO_tmfc(_X) memset(_X, 0, sizeof(TmFromChar))
444 #ifdef DEBUG_TO_FROM_CHAR
445 #define DEBUG_TMFC(_X) \
446 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", \
447 (_X)->mode, (_X)->hh, (_X)->pm, (_X)->mi, (_X)->ss, (_X)->ssss, \
448 (_X)->d, (_X)->dd, (_X)->ddd, (_X)->mm, (_X)->ms, (_X)->year, \
449 (_X)->bc, (_X)->ww, (_X)->w, (_X)->cc, (_X)->j, (_X)->us, \
450 (_X)->yysz, (_X)->clock)
451 #define DEBUG_TM(_X) \
452 elog(DEBUG_elog_output, "TM:\nsec %d\nyear %d\nmin %d\nwday %d\nhour %d\nyday %d\nmday %d\nnisdst %d\nmon %d\n",\
453 (_X)->tm_sec, (_X)->tm_year,\
454 (_X)->tm_min, (_X)->tm_wday, (_X)->tm_hour, (_X)->tm_yday,\
455 (_X)->tm_mday, (_X)->tm_isdst, (_X)->tm_mon)
457 #define DEBUG_TMFC(_X)
489 #define tmtcTm(_X) (&(_X)->tm)
490 #define tmtcTzn(_X) ((_X)->tzn)
491 #define tmtcFsec(_X) ((_X)->fsec)
494 #define COPY_tm(_DST, _SRC) \
496 (_DST)->tm_sec = (_SRC)->tm_sec; \
497 (_DST)->tm_min = (_SRC)->tm_min; \
498 (_DST)->tm_hour = (_SRC)->tm_hour; \
499 (_DST)->tm_mday = (_SRC)->tm_mday; \
500 (_DST)->tm_mon = (_SRC)->tm_mon; \
501 (_DST)->tm_year = (_SRC)->tm_year; \
502 (_DST)->tm_wday = (_SRC)->tm_wday; \
503 (_DST)->tm_yday = (_SRC)->tm_yday; \
504 (_DST)->tm_gmtoff = (_SRC)->tm_gmtoff; \
508 #define ZERO_tm(_X) \
510 memset(_X, 0, sizeof(*(_X))); \
511 (_X)->tm_mday = (_X)->tm_mon = 1; \
514 #define ZERO_tmtc(_X) \
516 ZERO_tm( tmtcTm(_X) ); \
518 tmtcTzn(_X) = NULL; \
525 #define INVALID_FOR_INTERVAL \
529 (errcode(ERRCODE_INVALID_DATETIME_FORMAT), \
530 errmsg("invalid format specification for an interval value"), \
531 errhint("Intervals are not tied to specific calendar dates."))); \
542 #define DCH_S_FM 0x01
543 #define DCH_S_TH 0x02
544 #define DCH_S_th 0x04
545 #define DCH_S_SP 0x08
546 #define DCH_S_TM 0x10
552 #define S_THth(_s) ((((_s) & DCH_S_TH) || ((_s) & DCH_S_th)) ? 1 : 0)
553 #define S_TH(_s) (((_s) & DCH_S_TH) ? 1 : 0)
554 #define S_th(_s) (((_s) & DCH_S_th) ? 1 : 0)
555 #define S_TH_TYPE(_s) (((_s) & DCH_S_TH) ? TH_UPPER : TH_LOWER)
558 #define S_FM(_s) (((_s) & DCH_S_FM) ? 1 : 0)
559 #define S_SP(_s) (((_s) & DCH_S_SP) ? 1 : 0)
560 #define S_TM(_s) (((_s) & DCH_S_TM) ? 1 : 0)
566 #define TM_SUFFIX_LEN 2
954 -1, -1, -1, -1, -1, -1, -1, -1,
955 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
956 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
957 -1, -1, -1, -1, -1,
DCH_A_D,
DCH_B_C,
DCH_CC,
DCH_DAY, -1,
958 DCH_FF1, -1,
DCH_HH24,
DCH_IDDD,
DCH_J, -1, -1,
DCH_MI, -1,
DCH_OF,
959 DCH_P_M,
DCH_Q,
DCH_RM,
DCH_SSSSS,
DCH_TZH,
DCH_US, -1,
DCH_WW, -1,
DCH_Y_YYY,
960 -1, -1, -1, -1, -1, -1, -1,
DCH_a_d,
DCH_b_c,
DCH_cc,
961 DCH_day, -1,
DCH_ff1, -1,
DCH_hh24,
DCH_iddd,
DCH_j, -1, -1,
DCH_mi,
962 -1,
DCH_of,
DCH_p_m,
DCH_q,
DCH_rm,
DCH_sssss,
DCH_tzh,
DCH_us, -1,
DCH_ww,
978 -1, -1, -1, -1, -1, -1, -1, -1,
979 -1, -1, -1, -1,
NUM_COMMA, -1,
NUM_DEC, -1,
NUM_0, -1,
980 -1, -1, -1, -1, -1, -1, -1,
NUM_9, -1, -1,
981 -1, -1, -1, -1, -1, -1,
NUM_B,
NUM_C,
NUM_D,
NUM_E,
982 NUM_FM,
NUM_G, -1, -1, -1, -1,
NUM_L,
NUM_MI, -1, -1,
983 NUM_PL, -1,
NUM_RN,
NUM_SG,
NUM_TH, -1,
NUM_V, -1, -1, -1,
984 -1, -1, -1, -1, -1, -1, -1, -1,
NUM_b,
NUM_c,
985 NUM_d,
NUM_e,
NUM_fm,
NUM_g, -1, -1, -1, -1,
NUM_l,
NUM_mi,
986 -1, -1,
NUM_pl, -1,
NUM_rn,
NUM_sg,
NUM_th, -1,
NUM_v, -1,
987 -1, -1, -1, -1, -1, -1
1026 #define DCH_DATED 0x01
1027 #define DCH_TIMED 0x02
1028 #define DCH_ZONED 0x04
1047 #ifdef DEBUG_TO_FROM_CHAR
1048 static void dump_index(
const KeyWord *k,
const int *
index);
1049 static void dump_node(
FormatNode *node,
int max);
1052 static const char *
get_th(
char *num,
int type);
1068 const char *
const *array,
1082 char *number,
int input_len,
int to_char_out_pre_spaces,
1106 if ((poz = *(
index + (*
str -
' '))) > -1)
1127 for (s = suf; s->
name != NULL; s++)
1142 return (*
str > 0x20 && *
str < 0x7F &&
1143 !(*
str >=
'A' && *
str <=
'Z') &&
1144 !(*
str >=
'a' && *
str <=
'z') &&
1145 !(*
str >=
'0' && *
str <=
'9'));
1160 (
errcode(ERRCODE_SYNTAX_ERROR),
1161 errmsg(
"\"EEEE\" must be the last pattern used")));
1168 (
errcode(ERRCODE_SYNTAX_ERROR),
1169 errmsg(
"\"9\" must be ahead of \"PR\"")));
1184 (
errcode(ERRCODE_SYNTAX_ERROR),
1185 errmsg(
"\"0\" must be ahead of \"PR\"")));
1211 (
errcode(ERRCODE_SYNTAX_ERROR),
1212 errmsg(
"multiple decimal points")));
1215 (
errcode(ERRCODE_SYNTAX_ERROR),
1216 errmsg(
"cannot use \"V\" and decimal point together")));
1227 (
errcode(ERRCODE_SYNTAX_ERROR),
1228 errmsg(
"cannot use \"S\" twice")));
1231 (
errcode(ERRCODE_SYNTAX_ERROR),
1232 errmsg(
"cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together")));
1251 (
errcode(ERRCODE_SYNTAX_ERROR),
1252 errmsg(
"cannot use \"S\" and \"MI\" together")));
1261 (
errcode(ERRCODE_SYNTAX_ERROR),
1262 errmsg(
"cannot use \"S\" and \"PL\" together")));
1271 (
errcode(ERRCODE_SYNTAX_ERROR),
1272 errmsg(
"cannot use \"S\" and \"SG\" together")));
1280 (
errcode(ERRCODE_SYNTAX_ERROR),
1281 errmsg(
"cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together")));
1298 (
errcode(ERRCODE_SYNTAX_ERROR),
1299 errmsg(
"cannot use \"V\" and decimal point together")));
1306 (
errcode(ERRCODE_SYNTAX_ERROR),
1307 errmsg(
"cannot use \"EEEE\" twice")));
1312 (
errcode(ERRCODE_SYNTAX_ERROR),
1313 errmsg(
"\"EEEE\" is incompatible with other formats"),
1314 errdetail(
"\"EEEE\" may only be used together with digit and decimal point patterns.")));
1333 #ifdef DEBUG_TO_FROM_CHAR
1334 elog(DEBUG_elog_output,
"to_char/number(): run parser");
1395 if (strchr(
"-./,':; ", *
str) == NULL)
1397 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
1398 errmsg(
"invalid datetime format separator: \"%s\"",
1413 else if (*
str ==
'"')
1427 if (*
str ==
'\\' && *(
str + 1))
1445 if (*
str ==
'\\' && *(
str + 1) ==
'"')
1451 else if (isspace((
unsigned char) *
str))
1474 #ifdef DEBUG_TO_FROM_CHAR
1476 #define DUMP_THth(_suf) (S_TH(_suf) ? "TH" : (S_th(_suf) ? "th" : " "))
1477 #define DUMP_FM(_suf) (S_FM(_suf) ? "FM" : " ")
1485 elog(DEBUG_elog_output,
"to_from-char(): DUMP FORMAT");
1487 for (
a = 0, n = node;
a <= max; n++,
a++)
1490 elog(DEBUG_elog_output,
"%d:\t NODE_TYPE_ACTION '%s'\t(%s,%s)",
1493 elog(DEBUG_elog_output,
"%d:\t NODE_TYPE_CHAR '%s'",
1497 elog(DEBUG_elog_output,
"%d:\t NODE_TYPE_END",
a);
1501 elog(DEBUG_elog_output,
"%d:\t unknown NODE!",
a);
1518 int len = strlen(num),
1521 last = *(num + (
len - 1));
1522 if (!isdigit((
unsigned char) last))
1524 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1525 errmsg(
"\"%s\" is not a number", num)));
1531 if ((
len > 1) && (num[
len - 2] ==
'1'))
1575 typedef int32_t (*ICU_Convert_Func) (UChar *
dest, int32_t destCapacity,
1576 const UChar *src, int32_t srcLength,
1578 UErrorCode *pErrorCode);
1581 icu_convert_case(ICU_Convert_Func func,
pg_locale_t mylocale,
1582 UChar **buff_dest, UChar *buff_source, int32_t len_source)
1587 len_dest = len_source;
1588 *buff_dest =
palloc(len_dest *
sizeof(**buff_dest));
1589 status = U_ZERO_ERROR;
1590 len_dest = func(*buff_dest, len_dest, buff_source, len_source,
1592 if (status == U_BUFFER_OVERFLOW_ERROR)
1596 *buff_dest =
palloc(len_dest *
sizeof(**buff_dest));
1597 status = U_ZERO_ERROR;
1598 len_dest = func(*buff_dest, len_dest, buff_source, len_source,
1601 if (U_FAILURE(status))
1603 (
errmsg(
"case conversion failed: %s", u_errorName(status))));
1608 u_strToTitle_default_BI(UChar *
dest, int32_t destCapacity,
1609 const UChar *src, int32_t srcLength,
1611 UErrorCode *pErrorCode)
1613 return u_strToTitle(
dest, destCapacity, src, srcLength,
1614 NULL,
locale, pErrorCode);
1650 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
1651 errmsg(
"could not determine which collation to use for %s function",
1653 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1668 if (mylocale && mylocale->
provider == COLLPROVIDER_ICU)
1675 len_uchar = icu_to_uchar(&buff_uchar, buff, nbytes);
1676 len_conv = icu_convert_case(u_strToLower, mylocale,
1677 &buff_conv, buff_uchar, len_uchar);
1678 icu_from_uchar(&result, buff_conv, len_conv);
1684 if (mylocale && mylocale->
provider == COLLPROVIDER_BUILTIN)
1686 const char *src = buff;
1687 size_t srclen = nbytes;
1695 dstsize = srclen + 1;
1699 if (needed + 1 > dstsize)
1702 dstsize = needed + 1;
1705 Assert(needed + 1 == dstsize);
1708 Assert(dst[needed] ==
'\0');
1722 if ((nbytes + 1) > (INT_MAX /
sizeof(
wchar_t)))
1724 (
errcode(ERRCODE_OUT_OF_MEMORY),
1725 errmsg(
"out of memory")));
1728 workspace = (
wchar_t *)
palloc((nbytes + 1) *
sizeof(wchar_t));
1730 char2wchar(workspace, nbytes + 1, buff, nbytes, mylocale);
1732 for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
1735 workspace[curr_char] =
towlower_l(workspace[curr_char], mylocale->
info.
lt);
1737 workspace[curr_char] = towlower(workspace[curr_char]);
1745 result =
palloc(result_size);
1747 wchar2char(result, workspace, result_size, mylocale);
1763 for (p = result; *p; p++)
1798 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
1799 errmsg(
"could not determine which collation to use for %s function",
1801 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1816 if (mylocale && mylocale->
provider == COLLPROVIDER_ICU)
1823 len_uchar = icu_to_uchar(&buff_uchar, buff, nbytes);
1824 len_conv = icu_convert_case(u_strToUpper, mylocale,
1825 &buff_conv, buff_uchar, len_uchar);
1826 icu_from_uchar(&result, buff_conv, len_conv);
1832 if (mylocale && mylocale->
provider == COLLPROVIDER_BUILTIN)
1834 const char *src = buff;
1835 size_t srclen = nbytes;
1843 dstsize = srclen + 1;
1847 if (needed + 1 > dstsize)
1850 dstsize = needed + 1;
1853 Assert(needed + 1 == dstsize);
1856 Assert(dst[needed] ==
'\0');
1870 if ((nbytes + 1) > (INT_MAX /
sizeof(
wchar_t)))
1872 (
errcode(ERRCODE_OUT_OF_MEMORY),
1873 errmsg(
"out of memory")));
1876 workspace = (
wchar_t *)
palloc((nbytes + 1) *
sizeof(wchar_t));
1878 char2wchar(workspace, nbytes + 1, buff, nbytes, mylocale);
1880 for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
1883 workspace[curr_char] =
towupper_l(workspace[curr_char], mylocale->
info.
lt);
1885 workspace[curr_char] = towupper(workspace[curr_char]);
1893 result =
palloc(result_size);
1895 wchar2char(result, workspace, result_size, mylocale);
1911 for (p = result; *p; p++)
1943 while (wbstate->
offset < wbstate->
len &&
1952 size_t prev_offset = wbstate->
offset;
1954 wbstate->
init =
true;
1963 return wbstate->
len;
1976 int wasalnum =
false;
1988 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
1989 errmsg(
"could not determine which collation to use for %s function",
1991 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
2006 if (mylocale && mylocale->
provider == COLLPROVIDER_ICU)
2013 len_uchar = icu_to_uchar(&buff_uchar, buff, nbytes);
2014 len_conv = icu_convert_case(u_strToTitle_default_BI, mylocale,
2015 &buff_conv, buff_uchar, len_uchar);
2016 icu_from_uchar(&result, buff_conv, len_conv);
2022 if (mylocale && mylocale->
provider == COLLPROVIDER_BUILTIN)
2024 const char *src = buff;
2025 size_t srclen = nbytes;
2034 .prev_alnum =
false,
2040 dstsize = srclen + 1;
2045 if (needed + 1 > dstsize)
2049 wbstate.
init =
false;
2052 dstsize = needed + 1;
2056 Assert(needed + 1 == dstsize);
2072 if ((nbytes + 1) > (INT_MAX /
sizeof(
wchar_t)))
2074 (
errcode(ERRCODE_OUT_OF_MEMORY),
2075 errmsg(
"out of memory")));
2078 workspace = (
wchar_t *)
palloc((nbytes + 1) *
sizeof(wchar_t));
2080 char2wchar(workspace, nbytes + 1, buff, nbytes, mylocale);
2082 for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
2087 workspace[curr_char] =
towlower_l(workspace[curr_char], mylocale->
info.
lt);
2089 workspace[curr_char] =
towupper_l(workspace[curr_char], mylocale->
info.
lt);
2095 workspace[curr_char] = towlower(workspace[curr_char]);
2097 workspace[curr_char] = towupper(workspace[curr_char]);
2098 wasalnum = iswalnum(workspace[curr_char]);
2107 result =
palloc(result_size);
2109 wchar2char(result, workspace, result_size, mylocale);
2125 for (p = result; *p; p++)
2141 wasalnum = isalnum((
unsigned char) *p);
2168 for (p = result; *p; p++)
2191 for (p = result; *p; p++)
2208 int wasalnum =
false;
2215 for (p = result; *p; p++)
2224 wasalnum = ((
c >=
'A' &&
c <=
'Z') ||
2225 (
c >=
'a' &&
c <=
'z') ||
2226 (
c >=
'0' &&
c <=
'9'));
2273 #define SKIP_THth(ptr, _suf) \
2277 if (*(ptr)) (ptr) += pg_mblen(ptr); \
2278 if (*(ptr)) (ptr) += pg_mblen(ptr); \
2283 #ifdef DEBUG_TO_FROM_CHAR
2296 elog(DEBUG_elog_output,
"TO-FROM_CHAR: Dump KeyWord Index:");
2308 elog(DEBUG_elog_output,
"\t(%d) %c %d",
i,
i + 32,
index[
i]);
2311 elog(DEBUG_elog_output,
"\n\t\tUsed positions: %d,\n\t\tFree positions: %d",
2346 isdigit((
unsigned char) n->
character[0]))
2364 else if (year < 100)
2367 else if (year < 520)
2370 else if (year < 1000)
2382 while (*
str && isspace((
unsigned char) *
str))
2409 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2410 errmsg(
"invalid combination of date conventions"),
2411 errhint(
"Do not mix Gregorian and ISO week date "
2412 "conventions in a formatting template.")));
2432 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2433 errmsg(
"conflicting values for \"%s\" field in formatting string",
2435 errdetail(
"This value contradicts a previous setting "
2436 "for the same field type.")));
2468 const char *
init = *src;
2488 result = strtol(
init, &endptr, 10);
2501 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2502 errmsg(
"source string too short for \"%s\" formatting field",
2504 errdetail(
"Field requires %d characters, but only %d remain.",
2506 errhint(
"If your source string is not fixed-width, "
2507 "try using the \"FM\" modifier.")));
2510 result = strtol(copy, &last, 10);
2513 if (used > 0 && used <
len)
2515 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2516 errmsg(
"invalid value \"%s\" for \"%s\"",
2518 errdetail(
"Field requires %d characters, but only %d could be parsed.",
2520 errhint(
"If your source string is not fixed-width, "
2521 "try using the \"FM\" modifier.")));
2528 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2529 errmsg(
"invalid value \"%s\" for \"%s\"",
2531 errdetail(
"Value must be an integer.")));
2533 if (errno == ERANGE || result < INT_MIN || result > INT_MAX)
2535 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2536 errmsg(
"value for \"%s\" in source string is out of range",
2538 errdetail(
"Value must be in the range %d to %d.",
2539 INT_MIN, INT_MAX)));
2580 unsigned char firstc;
2581 const char *
const *
a;
2592 for (
a = array; *
a != NULL;
a++)
2602 for (p = *
a + 1, n =
name + 1;; p++, n++)
2651 for (
a = array; *
a != NULL;
a++)
2653 int element_len = strlen(*
a);
2655 if (strncmp(
name, *
a, element_len) == 0)
2670 for (
a = array; *
a != NULL;
a++)
2672 char *upper_element;
2673 char *lower_element;
2678 lower_element =
str_tolower(upper_element, strlen(upper_element),
2680 pfree(upper_element);
2681 element_len = strlen(lower_element);
2684 if (strncmp(lower_name, lower_element, element_len) == 0)
2687 pfree(lower_element);
2691 pfree(lower_element);
2725 if (localized_array == NULL)
2739 for (
c = copy; *
c;
c++)
2749 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2750 errmsg(
"invalid value \"%s\" for \"%s\"",
2752 errdetail(
"The given value did not match any of "
2753 "the allowed values for this field.")));
2848 #define DCH_to_char_fsec(frac_fmt, frac_val) \
2849 sprintf(s, frac_fmt, (int) (frac_val)); \
2850 if (S_THth(n->suffix)) \
2851 str_numth(s, s, S_TH_TYPE(n->suffix)); \
2874 #undef DCH_to_char_fsec
2967 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2968 errmsg(
"localized string format value too long")));
2987 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2988 errmsg(
"localized string format value too long")));
3007 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3008 errmsg(
"localized string format value too long")));
3027 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3028 errmsg(
"localized string format value too long")));
3046 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3047 errmsg(
"localized string format value too long")));
3065 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3066 errmsg(
"localized string format value too long")));
3089 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3090 errmsg(
"localized string format value too long")));
3107 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3108 errmsg(
"localized string format value too long")));
3125 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3126 errmsg(
"localized string format value too long")));
3143 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3144 errmsg(
"localized string format value too long")));
3160 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3161 errmsg(
"localized string format value too long")));
3177 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3178 errmsg(
"localized string format value too long")));
3248 if (i <= 99 && i >= -99)
3289 is_interval)) % 1000);
3304 is_interval)) % 100);
3317 is_interval)) % 10);
3335 const char *
const *
months;
3436 while (*s !=
'\0' && isspace((
unsigned char) *s))
3457 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3458 errmsg(
"unmatched format separator \"%c\"",
3518 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3519 errmsg(
"unmatched format character \"%s\"",
3589 out->
ms *=
len == 1 ? 100 :
3605 out->
ff, n, escontext);
3609 out->
us *=
len == 1 ? 100000 :
3640 else if (isalpha((
unsigned char) *s))
3649 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3650 errmsg(
"invalid value \"%s\" for \"%s\"",
3652 errdetail(
"Time zone abbreviation is not recognized.")));
3660 if (*s ==
'+' || *s ==
'-' || *s ==
' ')
3662 out->
tzsign = *s ==
'-' ? -1 : +1;
3667 if (extra_skip > 0 && *(s - 1) ==
'-')
3691 if (*s ==
'+' || *s ==
'-' || *s ==
' ')
3693 out->
tzsign = *s ==
'-' ? -1 : +1;
3698 if (extra_skip > 0 && *(s - 1) ==
'-')
3849 matched = sscanf(s,
"%d,%03d%n", &millennia, &years, &nch);
3852 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3853 errmsg(
"invalid input string for \"Y,YYY\"")));
3854 years += (millennia * 1000);
3925 while (*s !=
'\0' && isspace((
unsigned char) *s))
3941 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3942 errmsg(
"input string is too short for datetime format")));
3944 while (*s !=
'\0' && isspace((
unsigned char) *s))
3949 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3950 errmsg(
"trailing characters remain in input string after datetime format")));
4087 #ifdef DEBUG_TO_FROM_CHAR
4104 #ifdef DEBUG_TO_FROM_CHAR
4105 elog(DEBUG_elog_output,
"OLD: '%s' AGE: %d", old->
str, old->
age);
4115 #ifdef DEBUG_TO_FROM_CHAR
4194 fmt_len = strlen(fmt_str);
4268 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4269 errmsg(
"timestamp out of range")));
4273 tt.
tm_wday = (thisdate + 1) % 7;
4304 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4305 errmsg(
"timestamp out of range")));
4309 tt.
tm_wday = (thisdate + 1) % 7;
4381 &
tm, &fsec, &ftz, &fprec, NULL, NULL);
4391 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4392 errmsg(
"timestamp out of range")));
4418 &
tm, &fsec, &ftz, NULL, NULL, NULL);
4423 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4424 errmsg(
"date out of range: \"%s\"",
4432 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4433 errmsg(
"date out of range: \"%s\"",
4456 Oid *typid,
int32 *typmod,
int *tz,
4466 &
tm, &fsec, &ftz, &fprec, &flags, escontext))
4469 *typmod = fprec ? fprec : -1;
4493 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4494 errmsg(
"missing time zone in input string for type timestamptz")));
4499 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4500 errmsg(
"timestamptz out of range")));
4504 *typid = TIMESTAMPTZOID;
4513 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4514 errmsg(
"timestamp out of range")));
4518 *typid = TIMESTAMPOID;
4527 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4528 errmsg(
"datetime format is zoned but not timed")));
4537 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4538 errmsg(
"date out of range: \"%s\"",
4547 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4548 errmsg(
"date out of range: \"%s\"",
4576 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4577 errmsg(
"missing time zone in input string for type timetz")));
4582 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4583 errmsg(
"timetz out of range")));
4596 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4597 errmsg(
"time out of range")));
4608 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4609 errmsg(
"datetime format is not dated and not timed")));
4621 int fmt_len = strlen(fmt_str);
4690 bool incache =
false;
4737 #ifdef DEBUG_TO_FROM_CHAR
4785 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4786 errmsg(
"hour \"%d\" is invalid for the 12-hour clock",
4788 errhint(
"Use the 24-hour clock, or give an hour between 1 and 12.")));
4806 if (tmfc.
cc && tmfc.
yysz <= 2)
4871 tmfc.
ddd = (tmfc.
ww - 1) * 7 + 1;
4875 tmfc.
dd = (tmfc.
w - 1) * 7 + 1;
4899 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4900 errmsg(
"cannot calculate day of year without year information")));
4918 static const int ysum[2][13] = {
4919 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
4920 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}};
4926 if (tmfc.
ddd <=
y[
i])
4940 *fsec += tmfc.
ms * 1000;
4960 date_str,
"timestamp", escontext);
4972 date_str,
"timestamp", escontext);
4988 date_str,
"timestamp", escontext);
5002 if (tmfc.
tzp == NULL)
5040 memset(
str,
c, max);
5041 *(
str + max) =
'\0';
5045 #define zeroize_NUM(_n) \
5051 (_n)->pre_lsign_num = 0; \
5052 (_n)->need_locale = 0; \
5054 (_n)->zero_start = 0; \
5055 (_n)->zero_end = 0; \
5086 #ifdef DEBUG_TO_FROM_CHAR
5103 #ifdef DEBUG_TO_FROM_CHAR
5104 elog(DEBUG_elog_output,
"OLD: \"%s\" AGE: %d", old->
str, old->
age);
5114 #ifdef DEBUG_TO_FROM_CHAR
5209 *shouldFree =
false;
5227 #ifdef DEBUG_TO_FROM_CHAR
5246 result = (
char *)
palloc(16);
5249 if (number > 3999 || number < 1)
5254 len =
snprintf(numstr,
sizeof(numstr),
"%d", number);
5256 for (p = numstr; *p !=
'\0'; p++, --
len)
5258 num = *p - (
'0' + 1);
5265 strcat(result,
"M");
5270 strcat(result,
rm100[num]);
5272 strcat(result,
rm10[num]);
5274 strcat(result,
rm1[num]);
5291 struct lconv *lconv;
5301 if (lconv->negative_sign && *lconv->negative_sign)
5306 if (lconv->positive_sign && *lconv->positive_sign)
5314 if (lconv->decimal_point && *lconv->decimal_point)
5315 Np->
decimal = lconv->decimal_point;
5330 if (lconv->thousands_sep && *lconv->thousands_sep)
5333 else if (strcmp(Np->
decimal,
",") != 0)
5341 if (lconv->currency_symbol && *lconv->currency_symbol)
5372 *p = strchr(num,
'.');
5374 #ifdef DEBUG_TO_FROM_CHAR
5375 elog(DEBUG_elog_output,
"get_last_relevant_decnum()");
5397 #define OVERLOAD_TEST (Np->inout_p >= Np->inout + input_len)
5398 #define AMOUNT_TEST(s) (Np->inout_p <= Np->inout + (input_len - (s)))
5407 bool isread =
false;
5409 #ifdef DEBUG_TO_FROM_CHAR
5410 elog(DEBUG_elog_output,
" --- scan start --- id=%s",
5429 #ifdef DEBUG_TO_FROM_CHAR
5430 elog(DEBUG_elog_output,
"Try read sign (%c), locale positive: %s, negative: %s",
5441 #ifdef DEBUG_TO_FROM_CHAR
5442 elog(DEBUG_elog_output,
"Try read locale pre-sign (%c)", *Np->
inout_p);
5461 #ifdef DEBUG_TO_FROM_CHAR
5462 elog(DEBUG_elog_output,
"Try read simple sign (%c)", *Np->
inout_p);
5485 #ifdef DEBUG_TO_FROM_CHAR
5486 elog(DEBUG_elog_output,
"Scan for numbers (%c), current number: '%s'", *Np->
inout_p, Np->
number);
5492 if (isdigit((
unsigned char) *Np->
inout_p))
5507 #ifdef DEBUG_TO_FROM_CHAR
5508 elog(DEBUG_elog_output,
"Read digit (%c)", *Np->
inout_p);
5520 #ifdef DEBUG_TO_FROM_CHAR
5521 elog(DEBUG_elog_output,
"Try read decimal point (%c)",
5555 !isdigit((
unsigned char) *(Np->
inout_p + 1)))
5560 #ifdef DEBUG_TO_FROM_CHAR
5561 elog(DEBUG_elog_output,
"Try read locale post-sign (%c)", *Np->
inout_p);
5592 else if (isread ==
false &&
IS_LSIGN(Np->
Num) ==
false &&
5595 #ifdef DEBUG_TO_FROM_CHAR
5596 elog(DEBUG_elog_output,
"Try read simple post-sign (%c)", *Np->
inout_p);
5609 #define IS_PREDEC_SPACE(_n) \
5610 (IS_ZERO((_n)->Num)==false && \
5611 (_n)->number == (_n)->number_p && \
5612 *(_n)->number == '0' && \
5613 (_n)->Num->post != 0)
5629 #ifdef DEBUG_TO_FROM_CHAR
5635 elog(DEBUG_elog_output,
5636 "SIGN_WROTE: %d, CURRENT: %d, NUMBER_P: \"%s\", INOUT: \"%s\"",
5656 if (Np->
sign ==
'-')
5670 else if (Np->
sign ==
'+')
5679 else if (Np->
sign ==
'-')
5794 if (Np->
sign ==
'-')
5816 if (strchr(
"0123456789.,+-", *Np->
inout_p) != NULL)
5824 char *number,
int input_len,
int to_char_out_pre_spaces,
5830 const char *pattern;
5851 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5852 errmsg(
"\"EEEE\" not supported for input")));
5853 return strcpy(inout, number);
5863 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5864 errmsg(
"\"RN\" not supported for input")));
5896 if (Np->
sign !=
'-')
5939 last_zero_pos = strlen(Np->
number) - 1;
5940 last_zero_pos =
Min(last_zero_pos,
5942 last_zero = Np->
number + last_zero_pos;
5955 *(Np->
number + 1) =
'\0';
5961 #ifdef DEBUG_TO_FROM_CHAR
5962 elog(DEBUG_elog_output,
5963 "\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",
6071 pattern_len = strlen(pattern);
6082 memset(Np->
inout_p,
' ', pattern_len);
6083 Np->
inout_p += pattern_len - 1;
6089 Np->
inout_p += pattern_len - 1;
6107 strncmp(Np->
inout_p, pattern, pattern_len) == 0)
6108 Np->
inout_p += pattern_len - 1;
6119 Np->
inout_p += strlen(pattern) - 1;
6193 if (Np->
sign ==
'-')
6215 if (Np->
sign ==
'+')
6295 #ifdef DEBUG_TO_FROM_CHAR
6296 elog(DEBUG_elog_output,
"TO_NUMBER (number): '%s'", Np->
number);
6307 #define NUM_TOCHAR_prepare \
6309 int len = VARSIZE_ANY_EXHDR(fmt); \
6310 if (len <= 0 || len >= (INT_MAX-VARHDRSZ)/NUM_MAX_ITEM_SIZ) \
6311 PG_RETURN_TEXT_P(cstring_to_text("")); \
6312 result = (text *) palloc0((len * NUM_MAX_ITEM_SIZ) + 1 + VARHDRSZ); \
6313 format = NUM_cache(len, &Num, fmt, &shouldFree); \
6320 #define NUM_TOCHAR_finish \
6324 NUM_processor(format, &Num, VARDATA(result), numstr, 0, out_pre_spaces, sign, true, PG_GET_COLLATION()); \
6334 len = strlen(VARDATA(result)); \
6335 SET_VARSIZE(result, len + VARHDRSZ); \
6410 int out_pre_spaces = 0,
6441 if (strcmp(orgnum,
"NaN") == 0 ||
6442 strcmp(orgnum,
"Infinity") == 0 ||
6443 strcmp(orgnum,
"-Infinity") == 0)
6452 *(numstr + Num.
pre + 1) =
'.';
6454 else if (*orgnum !=
'-')
6456 numstr = (
char *)
palloc(strlen(orgnum) + 2);
6458 strcpy(numstr + 1, orgnum);
6493 numstr = orgnum + 1;
6501 if ((p = strchr(numstr,
'.')))
6502 numstr_pre_len = p - numstr;
6504 numstr_pre_len = strlen(numstr);
6507 if (numstr_pre_len < Num.
pre)
6508 out_pre_spaces = Num.
pre - numstr_pre_len;
6510 else if (numstr_pre_len > Num.
pre)
6514 *(numstr + Num.
pre) =
'.';
6535 int out_pre_spaces = 0,
6586 numstr_pre_len = strlen(orgnum);
6591 numstr = (
char *)
palloc(numstr_pre_len + Num.
post + 2);
6592 strcpy(numstr, orgnum);
6593 *(numstr + numstr_pre_len) =
'.';
6594 memset(numstr + numstr_pre_len + 1,
'0', Num.
post);
6595 *(numstr + numstr_pre_len + Num.
post + 1) =
'\0';
6601 if (numstr_pre_len < Num.
pre)
6602 out_pre_spaces = Num.
pre - numstr_pre_len;
6604 else if (numstr_pre_len > Num.
pre)
6608 *(numstr + Num.
pre) =
'.';
6629 int out_pre_spaces = 0,
6657 numstr = (
char *)
palloc(strlen(orgnum) + 2);
6659 strcpy(numstr + 1, orgnum);
6672 double multi = pow((
double) 10, (
double) Num.
multi);
6692 numstr_pre_len = strlen(orgnum);
6697 numstr = (
char *)
palloc(numstr_pre_len + Num.
post + 2);
6698 strcpy(numstr, orgnum);
6699 *(numstr + numstr_pre_len) =
'.';
6700 memset(numstr + numstr_pre_len + 1,
'0', Num.
post);
6701 *(numstr + numstr_pre_len + Num.
post + 1) =
'\0';
6707 if (numstr_pre_len < Num.
pre)
6708 out_pre_spaces = Num.
pre - numstr_pre_len;
6710 else if (numstr_pre_len > Num.
pre)
6714 *(numstr + Num.
pre) =
'.';
6735 int out_pre_spaces = 0,
6755 *(numstr + Num.
pre + 1) =
'.';
6776 float multi = pow((
double) 10, (
double) Num.
multi);
6783 numstr_pre_len = strlen(orgnum);
6786 if (numstr_pre_len >= FLT_DIG)
6788 else if (numstr_pre_len + Num.
post > FLT_DIG)
6789 Num.
post = FLT_DIG - numstr_pre_len;
6795 numstr = orgnum + 1;
6803 if ((p = strchr(numstr,
'.')))
6804 numstr_pre_len = p - numstr;
6806 numstr_pre_len = strlen(numstr);
6809 if (numstr_pre_len < Num.
pre)
6810 out_pre_spaces = Num.
pre - numstr_pre_len;
6812 else if (numstr_pre_len > Num.
pre)
6816 *(numstr + Num.
pre) =
'.';
6837 int out_pre_spaces = 0,
6857 *(numstr + Num.
pre + 1) =
'.';
6878 double multi = pow((
double) 10, (
double) Num.
multi);
6885 numstr_pre_len = strlen(orgnum);
6888 if (numstr_pre_len >= DBL_DIG)
6890 else if (numstr_pre_len + Num.
post > DBL_DIG)
6891 Num.
post = DBL_DIG - numstr_pre_len;
6897 numstr = orgnum + 1;
6905 if ((p = strchr(numstr,
'.')))
6906 numstr_pre_len = p - numstr;
6908 numstr_pre_len = strlen(numstr);
6911 if (numstr_pre_len < Num.
pre)
6912 out_pre_spaces = Num.
pre - numstr_pre_len;
6914 else if (numstr_pre_len > Num.
pre)
6918 *(numstr + Num.
pre) =
'.';
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)
Datum numeric_round(PG_FUNCTION_ARGS)
Numeric int64_to_numeric(int64 val)
Datum numeric_power(PG_FUNCTION_ARGS)
Datum numeric_int4(PG_FUNCTION_ARGS)
Datum numeric_out(PG_FUNCTION_ARGS)
Datum numeric_in(PG_FUNCTION_ARGS)
char * numeric_out_sci(Numeric num, int scale)
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 unconstify(underlying_type, expr)
#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)
static void PGresult * res
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,...)
Datum Int64GetDatum(int64 X)
Datum Float8GetDatum(float8 X)
#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 int84(PG_FUNCTION_ARGS)
Datum int8mul(PG_FUNCTION_ARGS)
Datum dtoi8(PG_FUNCTION_ARGS)
Datum int4out(PG_FUNCTION_ARGS)
if(TABLE==NULL||TABLE_index==NULL)
static void const char * fmt
static pg_wchar utf8_to_unicode(const unsigned char *c)
int GetDatabaseEncoding(void)
int pg_mbstrlen(const char *mbstr)
int pg_database_encoding_max_length(void)
int pg_mblen(const char *mbstr)
char * pnstrdup(const char *in, Size len)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * MemoryContextAllocZero(MemoryContext context, Size size)
void * repalloc(void *pointer, Size size)
#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]
size_t wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
struct lconv * PGLC_localeconv(void)
pg_locale_t pg_newlocale_from_collation(Oid collid)
bool lc_ctype_is_c(Oid collation)
char * localized_abbrev_months[12+1]
char * localized_full_days[7+1]
char * localized_abbrev_days[7+1]
size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen, pg_locale_t locale)
#define MAX_MULTIBYTE_CHAR_LEN
static int unicode_utf8len(pg_wchar c)
PGDLLIMPORT pg_tz * session_timezone
unsigned char pg_toupper(unsigned char ch)
unsigned char pg_tolower(unsigned char ch)
unsigned char pg_ascii_tolower(unsigned char ch)
unsigned char pg_ascii_toupper(unsigned char ch)
size_t strlcpy(char *dst, const char *src, size_t siz)
static int64 DatumGetInt64(Datum X)
static char * DatumGetCString(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
char * psprintf(const char *fmt,...)
bool scanner_isspace(char ch)
FormatNode format[DCH_CACHE_SIZE+1]
char str[DCH_CACHE_SIZE+1]
FromCharDateMode date_mode
char str[NUM_CACHE_SIZE+1]
FormatNode format[NUM_CACHE_SIZE+1]
union pg_locale_struct::@151 info
size_t unicode_strlower(char *dst, size_t dstsize, const char *src, ssize_t srclen)
size_t unicode_strupper(char *dst, size_t dstsize, const char *src, ssize_t srclen)
size_t unicode_strtitle(char *dst, size_t dstsize, const char *src, ssize_t srclen, WordBoundaryNext wbnext, void *wbstate)
bool pg_u_isalnum(pg_wchar code, bool posix)
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)
#define VARSIZE_ANY_EXHDR(PTR)
char * text_to_cstring(const text *t)
text * cstring_to_text(const char *s)