117#define TEXTBUFLEN 1024
119#define DatumGetVarStringP(X) ((VarString *) PG_DETOAST_DATUM(X))
120#define DatumGetVarStringPP(X) ((VarString *) PG_DETOAST_DATUM_PACKED(X))
135 bool length_not_specified);
153 const char *fldsep,
const char *null_string);
159 int *argpos,
int *widthpos,
160 int *flags,
int *width);
164 int flags,
int width);
166 int flags,
int width);
254 if (dst_len >= src_len)
262 if (srcunpacked != src)
512 for (s = p; n > 0; n--)
598 if (length_not_specified)
605 (
errcode(ERRCODE_SUBSTRING_ERROR),
606 errmsg(
"negative substring length not allowed")));
661 if (length_not_specified)
663 slice_size = L1 = -1;
668 (
errcode(ERRCODE_SUBSTRING_ERROR),
669 errmsg(
"negative substring length not allowed")));
670 slice_size = L1 = -1;
678 slice_size = L1 = -1;
731 if (S1 > slice_strlen)
743 E1 =
Min(S1 + L1, slice_start + 1 + slice_strlen);
745 E1 = slice_start + 1 + slice_strlen;
751 for (
i = 0;
i < S1 - 1;
i++)
761 for (
i = S1;
i < E1;
i++)
766 memcpy(
VARDATA(ret), s, (p - s));
774 elog(
ERROR,
"invalid backend encoding: encoding max length < 1");
825 (
errcode(ERRCODE_SUBSTRING_ERROR),
826 errmsg(
"negative substring length not allowed")));
829 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
830 errmsg(
"integer out of range")));
889 state.greedy =
false;
930 state->greedy =
true;
944 state->is_multibyte_char_in_char =
false;
946 state->is_multibyte_char_in_char =
false;
948 state->is_multibyte_char_in_char =
true;
954 state->last_match = NULL;
971 if (len1 >= len2 && len2 > 1 &&
state->locale->deterministic)
973 int searchlength = len1 - len2;
977 const char *str2 =
state->str2;
991 if (searchlength < 16)
993 else if (searchlength < 64)
995 else if (searchlength < 128)
997 else if (searchlength < 512)
999 else if (searchlength < 2048)
1001 else if (searchlength < 4096)
1002 skiptablemask = 127;
1004 skiptablemask = 255;
1005 state->skiptablemask = skiptablemask;
1012 for (
i = 0;
i <= skiptablemask;
i++)
1013 state->skiptable[
i] = len2;
1024 for (
i = 0;
i < last;
i++)
1025 state->skiptable[(
unsigned char) str2[
i] & skiptablemask] = last -
i;
1040 int needle_len =
state->len2;
1044 if (needle_len <= 0)
1048 if (
state->last_match)
1049 start_ptr =
state->last_match +
state->last_match_len;
1051 start_ptr =
state->str1;
1065 if (
state->is_multibyte_char_in_char &&
state->locale->deterministic)
1072 while (
state->refpoint < matchptr)
1084 if (
state->refpoint > matchptr)
1086 start_ptr =
state->refpoint;
1092 state->last_match = matchptr;
1093 state->last_match_len =
state->last_match_len_tmp;
1105 int haystack_len =
state->len1;
1106 int needle_len =
state->len2;
1107 int skiptablemask =
state->skiptablemask;
1108 const char *haystack =
state->str1;
1109 const char *needle =
state->str2;
1110 const char *haystack_end = &haystack[haystack_len];
1113 Assert(start_ptr >= haystack && start_ptr <= haystack_end);
1116 state->last_match_len_tmp = needle_len;
1118 if (!
state->locale->deterministic)
1140 const char *result_hptr = NULL;
1143 while (hptr < haystack_end)
1145 const char *test_end;
1151 if (!
state->greedy &&
1152 haystack_end - hptr >= needle_len &&
1154 return (
char *) hptr;
1164 if (
pg_strncoll(hptr, (test_end - hptr), needle, needle_len,
state->locale) == 0)
1166 state->last_match_len_tmp = (test_end - hptr);
1171 }
while (test_end < haystack_end);
1179 return (
char *) result_hptr;
1181 else if (needle_len == 1)
1184 char nchar = *needle;
1187 while (hptr < haystack_end)
1190 return (
char *) hptr;
1196 const char *needle_last = &needle[needle_len - 1];
1199 hptr = start_ptr + needle_len - 1;
1200 while (hptr < haystack_end)
1224 hptr +=
state->skiptable[(
unsigned char) *hptr & skiptablemask];
1239 return state->last_match;
1254 return state->refpos + 1;
1266 state->last_match = NULL;
1288 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
1289 errmsg(
"could not determine which collation to use for string comparison"),
1290 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1319 result = memcmp(arg1, arg2,
Min(len1, len2));
1320 if ((result == 0) && (len1 != len2))
1321 result = (len1 < len2) ? -1 : 1;
1334 if (len1 == len2 && memcmp(arg1, arg2, len1) == 0)
1337 result =
pg_strncoll(arg1, len1, arg2, len2, mylocale);
1342 result = memcmp(arg1, arg2,
Min(len1, len2));
1343 if ((result == 0) && (len1 != len2))
1344 result = (len1 < len2) ? -1 : 1;
1561 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1562 errmsg(
"nondeterministic collations are not supported for substring searches")));
1629 bool collate_c =
false;
1650 if (
locale->collate_is_c)
1652 if (typid == BPCHAROID)
1654 else if (typid == NAMEOID)
1670 if (typid == NAMEOID)
1704 if (abbreviate || !collate_c)
1778 result = memcmp(a1p, a2p,
Min(len1, len2));
1779 if ((result == 0) && (len1 != len2))
1780 result = (len1 < len2) ? -1 : 1;
1815 result = memcmp(a1p, a2p,
Min(len1, len2));
1816 if ((result == 0) && (len1 != len2))
1817 result = (len1 < len2) ? -1 : 1;
1896 if (len1 == len2 && memcmp(a1p, a2p, len1) == 0)
1914 if (sss->
typid == BPCHAROID)
1943 if (len1 != sss->
last_len1 || memcmp(sss->
buf1, a1p, len1) != 0)
1946 memcpy(sss->
buf1, a1p, len1);
1947 sss->
buf1[len1] =
'\0';
1957 if (len2 != sss->
last_len2 || memcmp(sss->
buf2, a2p, len2) != 0)
1959 memcpy(sss->
buf2, a2p, len2);
1960 sss->
buf2[len2] =
'\0';
1973 result = strcmp(sss->
buf1, sss->
buf2);
1991 const size_t max_prefix_bytes =
sizeof(
Datum);
1994 char *authoritative_data =
VARDATA_ANY(authoritative);
2002 pres = (
char *) &res;
2004 memset(pres, 0, max_prefix_bytes);
2008 if (sss->
typid == BPCHAROID)
2039 memcpy(pres, authoritative_data,
Min(
len, max_prefix_bytes));
2058 memcmp(sss->
buf1, authoritative_data,
len) == 0)
2065 memcpy(sss->
buf1, authoritative_data,
len);
2075 if (sss->
buflen2 < max_prefix_bytes)
2083 max_prefix_bytes, sss->
locale);
2101 if (bsize < sss->buflen2)
2122 memcpy(pres, sss->
buf2,
Min(max_prefix_bytes, bsize));
2170 pfree(authoritative);
2184 double abbrev_distinct,
2190 if (memtupcount < 100)
2201 if (abbrev_distinct <= 1.0)
2202 abbrev_distinct = 1.0;
2204 if (key_distinct <= 1.0)
2214 double norm_abbrev_card = abbrev_distinct / (double) memtupcount;
2216 elog(
LOG,
"varstr_abbrev: abbrev_distinct after %d: %f "
2217 "(key_distinct: %f, norm_abbrev_card: %f, prop_card: %f)",
2218 memtupcount, abbrev_distinct, key_distinct, norm_abbrev_card,
2238 if (abbrev_distinct > key_distinct * sss->
prop_card)
2265 if (memtupcount > 10000)
2283 elog(
LOG,
"varstr_abbrev: aborted abbreviation at %d "
2284 "(abbrev_distinct: %f, key_distinct: %f, prop_card: %f)",
2285 memtupcount, abbrev_distinct, key_distinct, sss->
prop_card);
2342 size_t len1 = strlen(
NameStr(*arg1));
2349 if (
collid == C_COLLATION_OID)
2350 result = (len1 == len2 &&
2368 size_t len2 = strlen(
NameStr(*arg2));
2374 if (
collid == C_COLLATION_OID)
2375 result = (len1 == len2 &&
2392 size_t len1 = strlen(
NameStr(*arg1));
2399 if (
collid == C_COLLATION_OID)
2400 result = !(len1 == len2 &&
2418 size_t len2 = strlen(
NameStr(*arg2));
2424 if (
collid == C_COLLATION_OID)
2425 result = !(len1 == len2 &&
2469#define CmpCall(cmpfunc) \
2470 DatumGetInt32(DirectFunctionCall2Coll(cmpfunc, \
2471 PG_GET_COLLATION(), \
2472 PG_GETARG_DATUM(0), \
2473 PG_GETARG_DATUM(1)))
2547 else if (len1 < len2)
2549 else if (len1 > len2)
2710 (
errcode(ERRCODE_INVALID_NAME),
2711 errmsg(
"invalid name syntax")));
2713 if (namelist ==
NIL)
2715 (
errcode(ERRCODE_INVALID_NAME),
2716 errmsg(
"invalid name syntax")));
2718 foreach(l, namelist)
2720 char *curname = (
char *)
lfirst(l);
2758 char *nextp = rawstring;
2778 curname = nextp + 1;
2781 endp = strchr(nextp + 1,
'"');
2787 memmove(endp, endp + 1, strlen(endp));
2804 if (curname == nextp)
2816 len = endp - curname;
2819 strncpy(curname, downname,
len);
2833 else if (*nextp ==
'\0')
2847 *namelist =
lappend(*namelist, curname);
2885 char *nextp = rawstring;
2905 curname = nextp + 1;
2908 endp = strchr(nextp + 1,
'"');
2914 memmove(endp, endp + 1, strlen(endp));
2923 curname = endp = nextp;
2931 if (curname == endp)
2945 else if (*nextp ==
'\0')
2962 *namelist =
lappend(*namelist, curname);
3006 char *nextp = rawstring;
3026 curname = nextp + 1;
3029 endp = strchr(nextp + 1,
'"');
3035 memmove(endp, endp + 1, strlen(endp));
3049 if (curname == nextp)
3063 else if (*nextp ==
'\0')
3074 *namelist =
lappend(*namelist, curname);
3109 int from_sub_text_len;
3122 if (src_text_len < 1 || from_sub_text_len < 1)
3147 chunk_len = curr_ptr - start_ptr;
3152 start_ptr = curr_ptr +
state.last_match_len;
3161 chunk_len = ((
char *) src_text +
VARSIZE_ANY(src_text)) - start_ptr;
3189 p = memchr(p,
'\\', p_end - p);
3196 if (*p >=
'1' && *p <=
'9')
3215 char *start_ptr,
int data_pos)
3222 const char *chunk_start = p;
3227 p = memchr(p,
'\\', p_end - p);
3232 if (p > chunk_start)
3247 if (*p >=
'1' && *p <=
'9')
3252 so = pmatch[
idx].rm_so;
3253 eo = pmatch[
idx].rm_eo;
3259 so = pmatch[0].rm_so;
3260 eo = pmatch[0].rm_eo;
3263 else if (*p ==
'\\')
3281 if (so >= 0 && eo >= 0)
3291 chunk_start = start_ptr;
3315 int cflags,
Oid collation,
3316 int search_start,
int n)
3341 if (escape_status < 2)
3355 while (search_start <= data_len)
3377 pg_regerror(regexec_result, re, errMsg,
sizeof(errMsg));
3379 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
3380 errmsg(
"regular expression failed: %s", errMsg)));
3387 if (n > 0 && nmatches != n)
3394 search_start = pmatch[0].rm_eo;
3395 if (pmatch[0].rm_so == pmatch[0].rm_eo)
3404 if (pmatch[0].rm_so - data_pos > 0)
3409 pmatch[0].rm_so - data_pos);
3416 start_ptr += chunk_len;
3417 data_pos = pmatch[0].rm_so;
3423 if (escape_status > 0)
3425 start_ptr, data_pos);
3431 pmatch[0].rm_eo - data_pos);
3432 data_pos = pmatch[0].rm_eo;
3446 search_start = data_pos;
3447 if (pmatch[0].rm_so == pmatch[0].rm_eo)
3454 if (data_pos < data_len)
3458 chunk_len = ((
char *) src_text +
VARSIZE_ANY(src_text)) - start_ptr;
3480 int inputstring_len;
3491 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3492 errmsg(
"field position must not be zero")));
3498 if (inputstring_len < 1)
3505 if (fldnum == 1 || fldnum == -1)
3521 if (fldnum == 1 || fldnum == -1)
3543 end_ptr =
VARDATA_ANY(inputstring) + inputstring_len;
3546 end_ptr - start_ptr));
3550 fldnum += numfields + 1;
3569 while (found && --fldnum > 0)
3572 start_ptr = end_ptr +
state.last_match_len;
3586 int last_len = start_ptr -
VARDATA_ANY(inputstring);
3589 inputstring_len - last_len);
3626 memset(&tstate, 0,
sizeof(tstate));
3631 if (tstate.
astate == NULL)
3666 tstate.tupdesc = rsi->
setDesc;
3704 int inputstring_len;
3739 if (inputstring_len < 1)
3746 null_string, collation);
3766 chunk_len = ((
char *) inputstring +
VARSIZE_ANY(inputstring)) - start_ptr;
3773 chunk_len = end_ptr - start_ptr;
3781 null_string, collation);
3788 start_ptr = end_ptr +
state.last_match_len;
3804 while (inputstring_len > 0)
3806 int chunk_len =
pg_mblen(start_ptr);
3815 null_string, collation);
3819 start_ptr += chunk_len;
3820 inputstring_len -= chunk_len;
3839 bool is_null =
false;
3841 if (null_string &&
text_isequal(field_value, null_string, collation))
3916 const char *fldsep,
const char *null_string)
3927 bool printed =
false;
3951 if (my_extra == NULL)
3972 typlen = my_extra->
typlen;
3986 if (bitmap && (*bitmap & bitmask) == 0)
3989 if (null_string != NULL)
4000 itemvalue =
fetch_att(p, typbyval, typlen);
4018 if (bitmask == 0x100)
4039 const char *
digits =
"0123456789abcdef";
4043 char *
const end =
buf +
sizeof(
buf);
4128 if (fcinfo->flinfo->fn_extra == NULL)
4135 elog(
ERROR,
"cache lookup failed for type %u", argtypeid);
4139 *((
int *) fcinfo->flinfo->fn_extra) = typlen;
4142 typlen = *((
int *) fcinfo->flinfo->fn_extra);
4149 else if (typlen == -2)
4175 if (fcinfo->flinfo->fn_extra == NULL)
4182 elog(
ERROR,
"cache lookup failed for type %u", argtypeid);
4186 *((
int *) fcinfo->flinfo->fn_extra) = typlen;
4189 typlen = *((
int *) fcinfo->flinfo->fn_extra);
4210 elog(
ERROR,
"invalid compression method id %d", cmid);
4228 if (fcinfo->flinfo->fn_extra == NULL)
4235 elog(
ERROR,
"cache lookup failed for type %u", argtypeid);
4239 *((
int *) fcinfo->flinfo->fn_extra) = typlen;
4242 typlen = *((
int *) fcinfo->flinfo->fn_extra);
4278 elog(
ERROR,
"string_agg_transfn called in non-aggregate context");
4303 bool isfirst =
false;
4355 elog(
ERROR,
"aggregate function called in non-aggregate context");
4382 else if (state2->
len > 0)
4508 elog(
ERROR,
"could not determine data type of concat() input");
4535 bool first_arg =
true;
4578 if (foutcache == NULL)
4695 const char *endp = p +
len;
4730#define TEXT_FORMAT_FLAG_MINUS 0x0001
4732#define ADVANCE_PARSE_POINTER(ptr,end_ptr) \
4734 if (++(ptr) >= (end_ptr)) \
4736 (errcode(ERRCODE_INVALID_PARAMETER_VALUE), \
4737 errmsg("unterminated format() type specifier"), \
4738 errhint("For a single \"%%\" use \"%%%%\"."))); \
4750 const char *start_ptr;
4751 const char *end_ptr;
4756 Datum *elements = NULL;
4800 &elmlen, &elmbyval, &elmalign);
4804 &elements, &nulls, &
nitems);
4808 funcvariadic =
true;
4814 funcvariadic =
false;
4825 for (cp = start_ptr; cp < end_ptr; cp++)
4867 if (strchr(
"sIL", *cp) == NULL)
4869 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4870 errmsg(
"unrecognized format() type specifier \"%.*s\"",
4872 errhint(
"For a single \"%%\" use \"%%%%\".")));
4882 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4883 errmsg(
"too few arguments for format()")));
4895 isNull = nulls[
arg - 1];
4896 typid = element_type;
4899 elog(
ERROR,
"could not determine data type of format() input");
4906 else if (typid == INT4OID)
4908 else if (typid == INT2OID)
4915 if (typid != prev_width_type)
4921 fmgr_info(typoutputfunc, &typoutputinfo_width);
4922 prev_width_type = typid;
4939 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4940 errmsg(
"too few arguments for format()")));
4952 isNull = nulls[
arg - 1];
4953 typid = element_type;
4956 elog(
ERROR,
"could not determine data type of format() input");
4965 if (typid != prev_type)
4971 fmgr_info(typoutputfunc, &typoutputfinfo);
4990 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4991 errmsg(
"unrecognized format() type specifier \"%.*s\"",
4993 errhint(
"For a single \"%%\" use \"%%%%\".")));
4999 if (elements != NULL)
5025 const char *cp = *ptr;
5028 while (*cp >=
'0' && *cp <=
'9')
5030 int8 digit = (*cp -
'0');
5035 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
5036 errmsg(
"number is out of range")));
5072 int *argpos,
int *widthpos,
5073 int *flags,
int *width)
5075 const char *cp = start_ptr;
5098 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5099 errmsg(
"format specifies argument 0, but arguments are numbered from 1")));
5119 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5120 errmsg(
"width argument position must be ended by \"$\"")));
5126 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5127 errmsg(
"format specifies argument 0, but arguments are numbered from 1")));
5151 int flags,
int width)
5158 if (conversion ==
's')
5160 else if (conversion ==
'L')
5162 else if (conversion ==
'I')
5164 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5165 errmsg(
"null values cannot be formatted as an SQL identifier")));
5173 if (conversion ==
'I')
5178 else if (conversion ==
'L')
5198 int flags,
int width)
5200 bool align_to_left =
false;
5213 align_to_left =
true;
5215 if (width <= INT_MIN)
5217 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
5218 errmsg(
"number is out of range")));
5222 align_to_left =
true;
5272#define LEVENSHTEIN_LESS_EQUAL
5302 state->max_d = max_d;
5303 state->match = NULL;
5321 if (
state->source == NULL ||
state->source[0] ==
'\0' ||
5322 candidate == NULL || candidate[0] ==
'\0')
5334 candidate, strlen(candidate), 1, 1, 1,
5335 state->max_d,
true);
5336 if (dist <= state->max_d &&
5337 dist <= strlen(
state->source) / 2 &&
5338 (
state->min_d == -1 || dist < state->min_d))
5340 state->min_d = dist;
5341 state->match = candidate;
5354 return state->match;
5372 (
errcode(ERRCODE_SYNTAX_ERROR),
5373 errmsg(
"Unicode normalization can only be performed if server encoding is UTF8")));
5385 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5386 errmsg(
"invalid normalization form: %s", formstr)));
5431 (
errmsg(
"Unicode categorization can only be performed if server encoding is UTF8")));
5436 for (
int i = 0;
i < size;
i++)
5457 char32_t *input_chars;
5458 char32_t *output_chars;
5467 input_chars =
palloc((size + 1) *
sizeof(
char32_t));
5469 for (
i = 0;
i < size;
i++)
5482 for (
char32_t *wp = output_chars; *wp; wp++)
5484 unsigned char buf[4];
5494 for (
char32_t *wp = output_chars; *wp; wp++)
5523 char32_t *input_chars;
5524 char32_t *output_chars;
5535 input_chars =
palloc((size + 1) *
sizeof(
char32_t));
5537 for (
i = 0;
i < size;
i++)
5556 for (
char32_t *wp = output_chars; *wp; wp++)
5559 result = (size == output_size) &&
5560 (memcmp(input_chars, output_chars, size *
sizeof(
char32_t)) == 0);
5571 for (
size_t i = 0;
i < n;
i++)
5572 if (!isxdigit((
unsigned char) instr[
i]))
5581 if (
c >=
'0' &&
c <=
'9')
5583 if (
c >=
'a' &&
c <=
'f')
5584 return c -
'a' + 0xA;
5585 if (
c >=
'A' &&
c <=
'F')
5586 return c -
'A' + 0xA;
5587 elog(
ERROR,
"invalid hexadecimal digit");
5597 unsigned int result = 0;
5599 for (
size_t i = 0;
i < n;
i++)
5600 result +=
hexval(instr[
i]) << (4 * (n -
i - 1));
5616 char16_t pair_first = 0;
5626 if (instr[0] ==
'\\')
5641 int offset = instr[1] ==
'u' ? 2 : 1;
5643 unicode =
hexval_n(instr + offset, 4);
5647 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5648 errmsg(
"invalid Unicode code point: %04X", unicode));
5664 pair_first = unicode;
5671 instr += 4 + offset;
5674 else if (
len >= 8 && instr[1] ==
'+' &&
isxdigits_n(instr + 2, 6))
5682 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5683 errmsg(
"invalid Unicode code point: %04X", unicode));
5699 pair_first = unicode;
5709 else if (
len >= 10 && instr[1] ==
'U' &&
isxdigits_n(instr + 2, 8))
5717 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5718 errmsg(
"invalid Unicode code point: %04X", unicode));
5734 pair_first = unicode;
5746 (
errcode(ERRCODE_SYNTAX_ERROR),
5747 errmsg(
"invalid Unicode escape"),
5748 errhint(
"Unicode escapes must be \\XXXX, \\+XXXXXX, \\uXXXX, or \\UXXXXXXXX.")));
5771 (
errcode(ERRCODE_SYNTAX_ERROR),
5772 errmsg(
"invalid Unicode surrogate pair")));
Datum idx(PG_FUNCTION_ARGS)
#define PG_GETARG_ARRAYTYPE_P(n)
#define ARR_NULLBITMAP(a)
#define PG_RETURN_ARRAYTYPE_P(x)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayType * construct_empty_array(Oid elmtype)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
void deconstruct_array(const ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
int ArrayGetNItems(int ndim, const int *dims)
static Datum values[MAXATTR]
#define TextDatumGetCString(d)
#define unconstify(underlying_type, expr)
#define OidIsValid(objectId)
Size toast_datum_size(Datum value)
Size toast_raw_datum_size(Datum value)
#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_object(type)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
bool get_fn_expr_variadic(FmgrInfo *flinfo)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_GETARG_BYTEA_PP(n)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define DatumGetTextPP(X)
#define DatumGetBpCharPP(X)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_GETARG_NAME(n)
#define PG_RETURN_TEXT_P(x)
#define DatumGetTextPSlice(X, m, n)
#define PG_RETURN_INT32(x)
#define PG_RETURN_NAME(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_GET_COLLATION()
#define PG_RETURN_BOOL(x)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
#define MAT_SRF_USE_EXPECTED_DESC
static Datum hash_uint32(uint32 k)
static Datum hash_any(const unsigned char *k, int keylen)
Assert(PointerIsAligned(start, uint64))
void initHyperLogLog(hyperLogLogState *cState, uint8 bwidth)
double estimateHyperLogLog(hyperLogLogState *cState)
void addHyperLogLog(hyperLogLogState *cState, uint32 hash)
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
if(TABLE==NULL||TABLE_index==NULL)
#define MAX_LEVENSHTEIN_STRLEN
List * lappend(List *list, void *datum)
void list_free(List *list)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
void get_type_io_data(Oid typid, IOFuncSelector which_func, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *func)
int16 get_typlen(Oid typid)
Oid get_base_element_type(Oid typid)
static char32_t utf8_to_unicode(const unsigned char *c)
int GetDatabaseEncoding(void)
int pg_mbstrlen_with_len(const char *mbstr, int limit)
int pg_mbcharcliplen(const char *mbstr, int len, int limit)
int pg_mbstrlen(const char *mbstr)
int pg_mbcliplen(const char *mbstr, int len, int limit)
int pg_database_encoding_max_length(void)
void pg_unicode_to_server(char32_t c, unsigned char *s)
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
int pg_mblen(const char *mbstr)
void * MemoryContextAlloc(MemoryContext context, Size size)
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
#define CHECK_FOR_INTERRUPTS()
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
int32 pg_strtoint32(const char *s)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define DatumBigEndianToNative(x)
#define PG_CACHE_LINE_SIZE
bool pg_strxfrm_enabled(pg_locale_t locale)
pg_locale_t pg_newlocale_from_collation(Oid collid)
int pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale)
bool pg_strxfrm_prefix_enabled(pg_locale_t locale)
int pg_strncoll(const char *arg1, ssize_t len1, const char *arg2, ssize_t len2, pg_locale_t locale)
size_t pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
size_t pg_strxfrm_prefix(char *dest, const char *src, size_t destsize, pg_locale_t locale)
static rewind_source * source
static char buf[DEFAULT_XLOG_SEG_SIZE]
static bool is_utf16_surrogate_first(char32_t c)
static unsigned char * unicode_to_utf8(char32_t c, unsigned char *utf8string)
static bool is_utf16_surrogate_second(char32_t c)
static char32_t surrogate_pair_to_codepoint(char16_t first, char16_t second)
#define MAX_UNICODE_EQUIVALENT_STRING
static bool is_valid_unicode_codepoint(char32_t c)
int pg_strcasecmp(const char *s1, const char *s2)
void canonicalize_path(char *path)
static uint32 DatumGetUInt32(Datum X)
static uint64 DatumGetUInt64(Datum X)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Name DatumGetName(Datum X)
static char * DatumGetCString(Datum X)
static Pointer DatumGetPointer(Datum X)
static int16 DatumGetInt16(Datum X)
static int32 DatumGetInt32(Datum X)
char * quote_literal_cstr(const char *rawstr)
static unsigned hash(unsigned *uv, int n)
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
int pg_regexec(regex_t *re, const chr *string, size_t len, size_t search_start, rm_detail_t *details, size_t nmatch, regmatch_t pmatch[], int flags)
regex_t * RE_compile_and_cache(text *text_re, int cflags, Oid collation)
const char * quote_identifier(const char *ident)
void truncate_identifier(char *ident, int len, bool warn)
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
bool scanner_isspace(char ch)
struct SortSupportData * SortSupport
struct StringInfoData * StringInfo
StringInfo makeStringInfo(void)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoSpaces(StringInfo str, int count)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
#define appendStringInfoCharMacro(str, ch)
static void initReadOnlyStringInfo(StringInfo str, char *data, int len)
Tuplestorestate * setResult
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Datum(* abbrev_converter)(Datum original, SortSupport ssup)
int(* abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup)
bool(* abbrev_abort)(int memtupcount, SortSupport ssup)
Tuplestorestate * tupstore
bool is_multibyte_char_in_char
hyperLogLogState full_card
hyperLogLogState abbr_card
ToastCompressionId toast_get_compression_id(struct varlena *attr)
@ TOAST_INVALID_COMPRESSION_ID
@ TOAST_LZ4_COMPRESSION_ID
@ TOAST_PGLZ_COMPRESSION_ID
int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
#define att_align_nominal(cur_offset, attalign)
#define att_addlength_pointer(cur_offset, attlen, attptr)
static Datum fetch_att(const void *T, bool attbyval, int attlen)
pg_unicode_category unicode_category(char32_t code)
UnicodeNormalizationQC unicode_is_normalized_quickcheck(UnicodeNormalizationForm form, const char32_t *input)
char32_t * unicode_normalize(UnicodeNormalizationForm form, const char32_t *input)
#define PG_UNICODE_VERSION
String * makeString(char *str)
static bool VARATT_IS_EXTERNAL_ONDISK(const void *PTR)
static Size VARSIZE_ANY(const void *PTR)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static bool VARATT_IS_EXTERNAL(const void *PTR)
static char * VARDATA(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
static bool VARATT_IS_COMPRESSED(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)
int bpchartruelen(char *s, int len)
static int varstrfastcmp_locale(char *a1p, int len1, char *a2p, int len2, SortSupport ssup)
Datum unknownrecv(PG_FUNCTION_ARGS)
Datum array_to_text(PG_FUNCTION_ARGS)
static int text_cmp(text *arg1, text *arg2, Oid collid)
Datum textsend(PG_FUNCTION_ARGS)
Datum textoverlay_no_len(PG_FUNCTION_ARGS)
static void text_format_string_conversion(StringInfo buf, char conversion, FmgrInfo *typOutputInfo, Datum value, bool isNull, int flags, int width)
static text * text_overlay(text *t1, text *t2, int sp, int sl)
Datum text_format(PG_FUNCTION_ARGS)
Datum textlen(PG_FUNCTION_ARGS)
Datum pg_column_toast_chunk_id(PG_FUNCTION_ARGS)
static void text_position_setup(text *t1, text *t2, Oid collid, TextPositionState *state)
static int32 text_length(Datum str)
static bool varstr_abbrev_abort(int memtupcount, SortSupport ssup)
Datum text_left(PG_FUNCTION_ARGS)
Datum string_agg_transfn(PG_FUNCTION_ARGS)
static bool text_isequal(text *txt1, text *txt2, Oid collid)
static void text_position_cleanup(TextPositionState *state)
static text * text_catenate(text *t1, text *t2)
static text * concat_internal(const char *sepstr, int argidx, FunctionCallInfo fcinfo)
static void appendStringInfoText(StringInfo str, const text *t)
Datum textgtname(PG_FUNCTION_ARGS)
Datum textout(PG_FUNCTION_ARGS)
Datum textcat(PG_FUNCTION_ARGS)
Datum text_substr(PG_FUNCTION_ARGS)
Datum text_smaller(PG_FUNCTION_ARGS)
static text * text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
static int check_replace_text_has_escape(const text *replace_text)
Datum text_concat_ws(PG_FUNCTION_ARGS)
static int internal_text_pattern_compare(text *arg1, text *arg2)
Datum string_agg_serialize(PG_FUNCTION_ARGS)
Datum text_ge(PG_FUNCTION_ARGS)
static int varlenafastcmp_locale(Datum x, Datum y, SortSupport ssup)
Datum array_to_text_null(PG_FUNCTION_ARGS)
static const char * text_format_parse_format(const char *start_ptr, const char *end_ptr, int *argpos, int *widthpos, int *flags, int *width)
Datum text_larger(PG_FUNCTION_ARGS)
Datum unicode_assigned(PG_FUNCTION_ARGS)
int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
static char * text_position_get_match_ptr(TextPositionState *state)
static int bpcharfastcmp_c(Datum x, Datum y, SortSupport ssup)
Datum text_to_array_null(PG_FUNCTION_ARGS)
static unsigned int hexval_n(const char *instr, size_t n)
static bool rest_of_char_same(const char *s1, const char *s2, int len)
text * cstring_to_text_with_len(const char *s, int len)
Datum text_to_table_null(PG_FUNCTION_ARGS)
Datum text_right(PG_FUNCTION_ARGS)
Datum textne(PG_FUNCTION_ARGS)
Datum textrecv(PG_FUNCTION_ARGS)
static void text_format_append_string(StringInfo buf, const char *str, int flags, int width)
static int text_position(text *t1, text *t2, Oid collid)
bool SplitDirectoriesString(char *rawstring, char separator, List **namelist)
Datum unicode_normalize_func(PG_FUNCTION_ARGS)
Datum bttext_pattern_sortsupport(PG_FUNCTION_ARGS)
static void split_text_accum_result(SplitTextOutputData *tstate, text *field_value, text *null_string, Oid collation)
Datum split_part(PG_FUNCTION_ARGS)
Datum texteqname(PG_FUNCTION_ARGS)
Datum text_substr_no_len(PG_FUNCTION_ARGS)
Datum text_name(PG_FUNCTION_ARGS)
Datum text_le(PG_FUNCTION_ARGS)
const char * getClosestMatch(ClosestMatchState *state)
static void text_position_reset(TextPositionState *state)
Datum text_to_table(PG_FUNCTION_ARGS)
#define ADVANCE_PARSE_POINTER(ptr, end_ptr)
Datum textnename(PG_FUNCTION_ARGS)
static char * text_position_next_internal(char *start_ptr, TextPositionState *state)
static FmgrInfo * build_concat_foutcache(FunctionCallInfo fcinfo, int argidx)
Datum to_hex64(PG_FUNCTION_ARGS)
Datum text_to_array(PG_FUNCTION_ARGS)
Datum unicode_is_normalized(PG_FUNCTION_ARGS)
#define TEXT_FORMAT_FLAG_MINUS
static void check_collation_set(Oid collid)
bool SplitGUCList(char *rawstring, char separator, List **namelist)
static text * convert_to_base(uint64 value, int base)
Datum textoverlay(PG_FUNCTION_ARGS)
static void appendStringInfoRegexpSubstr(StringInfo str, text *replace_text, regmatch_t *pmatch, char *start_ptr, int data_pos)
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
static text * array_to_text_internal(FunctionCallInfo fcinfo, ArrayType *v, const char *fldsep, const char *null_string)
Datum to_hex32(PG_FUNCTION_ARGS)
Datum text_starts_with(PG_FUNCTION_ARGS)
Datum text_gt(PG_FUNCTION_ARGS)
Datum text_reverse(PG_FUNCTION_ARGS)
Datum to_bin64(PG_FUNCTION_ARGS)
Datum texteq(PG_FUNCTION_ARGS)
Datum to_oct64(PG_FUNCTION_ARGS)
Datum text_pattern_gt(PG_FUNCTION_ARGS)
static int charlen_to_bytelen(const char *p, int n)
void varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
static int namefastcmp_c(Datum x, Datum y, SortSupport ssup)
static StringInfo makeStringAggState(FunctionCallInfo fcinfo)
Datum textlename(PG_FUNCTION_ARGS)
Datum icu_unicode_version(PG_FUNCTION_ARGS)
static int namefastcmp_locale(Datum x, Datum y, SortSupport ssup)
static Datum varstr_abbrev_convert(Datum original, SortSupport ssup)
text * cstring_to_text(const char *s)
Datum text_concat(PG_FUNCTION_ARGS)
Datum text_pattern_lt(PG_FUNCTION_ARGS)
Datum text_pattern_ge(PG_FUNCTION_ARGS)
Datum btvarstrequalimage(PG_FUNCTION_ARGS)
Datum nameletext(PG_FUNCTION_ARGS)
text * replace_text_regexp(text *src_text, text *pattern_text, text *replace_text, int cflags, Oid collation, int search_start, int n)
Datum namenetext(PG_FUNCTION_ARGS)
static int text_position_get_match_pos(TextPositionState *state)
void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len)
Datum to_bin32(PG_FUNCTION_ARGS)
Datum to_oct32(PG_FUNCTION_ARGS)
Datum namegttext(PG_FUNCTION_ARGS)
Datum unicode_version(PG_FUNCTION_ARGS)
Datum namegetext(PG_FUNCTION_ARGS)
static UnicodeNormalizationForm unicode_norm_form_from_string(const char *formstr)
static bool text_position_next(TextPositionState *state)
Datum textoctetlen(PG_FUNCTION_ARGS)
Datum textltname(PG_FUNCTION_ARGS)
Datum bttextsortsupport(PG_FUNCTION_ARGS)
Datum text_format_nv(PG_FUNCTION_ARGS)
Datum textpos(PG_FUNCTION_ARGS)
static int varstrfastcmp_c(Datum x, Datum y, SortSupport ssup)
Datum bttext_pattern_cmp(PG_FUNCTION_ARGS)
Datum string_agg_finalfn(PG_FUNCTION_ARGS)
Datum unistr(PG_FUNCTION_ARGS)
static unsigned int hexval(unsigned char c)
static bool text_format_parse_digits(const char **ptr, const char *end_ptr, int *value)
Datum unknownin(PG_FUNCTION_ARGS)
static bool isxdigits_n(const char *instr, size_t n)
Datum string_agg_deserialize(PG_FUNCTION_ARGS)
Datum namelttext(PG_FUNCTION_ARGS)
Datum pg_column_size(PG_FUNCTION_ARGS)
#define DatumGetVarStringPP(X)
Datum pg_column_compression(PG_FUNCTION_ARGS)
Datum name_text(PG_FUNCTION_ARGS)
Datum nameeqtext(PG_FUNCTION_ARGS)
Datum bttextnamecmp(PG_FUNCTION_ARGS)
void initClosestMatch(ClosestMatchState *state, const char *source, int max_d)
Datum textin(PG_FUNCTION_ARGS)
Datum string_agg_combine(PG_FUNCTION_ARGS)
Datum btnametextcmp(PG_FUNCTION_ARGS)
Datum unknownsend(PG_FUNCTION_ARGS)
Datum text_pattern_le(PG_FUNCTION_ARGS)
void updateClosestMatch(ClosestMatchState *state, const char *candidate)
char * text_to_cstring(const text *t)
Datum bttextcmp(PG_FUNCTION_ARGS)
Datum unknownout(PG_FUNCTION_ARGS)
Datum replace_text(PG_FUNCTION_ARGS)
Datum textgename(PG_FUNCTION_ARGS)
List * textToQualifiedNameList(text *textval)
static bool split_text(FunctionCallInfo fcinfo, SplitTextOutputData *tstate)
Datum text_lt(PG_FUNCTION_ARGS)
int varstr_levenshtein_less_equal(const char *source, int slen, const char *target, int tlen, int ins_c, int del_c, int sub_c, int max_d, bool trusted)