32 #include "utils/fmgroids.h"
43 #define JB_PATH_CREATE 0x0001
44 #define JB_PATH_DELETE 0x0002
45 #define JB_PATH_REPLACE 0x0004
46 #define JB_PATH_INSERT_BEFORE 0x0008
47 #define JB_PATH_INSERT_AFTER 0x0010
48 #define JB_PATH_CREATE_OR_INSERT \
49 (JB_PATH_INSERT_BEFORE | JB_PATH_INSERT_AFTER | JB_PATH_CREATE)
50 #define JB_PATH_FILL_GAPS 0x0020
51 #define JB_PATH_CONSISTENT_POSITION 0x0040
318 #define JsValueIsNull(jsv) \
320 (!(jsv)->val.json.str || (jsv)->val.json.type == JSON_TOKEN_NULL) : \
321 (!(jsv)->val.jsonb || (jsv)->val.jsonb->type == jbvNull))
323 #define JsValueIsString(jsv) \
324 ((jsv)->is_json ? (jsv)->val.json.type == JSON_TOKEN_STRING \
325 : ((jsv)->val.jsonb && (jsv)->val.jsonb->type == jbvString))
327 #define JsObjectIsEmpty(jso) \
329 ? hash_get_num_entries((jso)->val.json_hash) == 0 \
330 : ((jso)->val.jsonb_cont == NULL || \
331 JsonContainerSize((jso)->val.jsonb_cont) == 0))
333 #define JsObjectFree(jso) \
335 if ((jso)->is_json) \
336 hash_destroy((jso)->val.json_hash); \
360 bool normalize_results);
429 bool is_json,
bool have_record_arg);
431 bool is_json,
bool have_record_arg,
450 bool *isnull,
Node *escontext);
478 bool *path_nulls,
int path_len,
574 bool skipNested =
false;
581 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
582 errmsg(
"cannot call %s on a scalar",
583 "jsonb_object_keys")));
586 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
587 errmsg(
"cannot call %s on an array",
588 "jsonb_object_keys")));
596 state->result_count = 0;
597 state->sent_count = 0;
610 cstr =
palloc(v.
val.string.len + 1 *
sizeof(
char));
611 memcpy(cstr, v.
val.string.val, v.
val.string.len);
612 cstr[v.
val.string.len] =
'\0';
626 char *nxt =
state->result[
state->sent_count++];
645 (
errcode(ERRCODE_UNTRANSLATABLE_CHARACTER),
646 errmsg(
"unsupported Unicode escape sequence"),
653 elog(
ERROR,
"JSON semantic action function did not provide error information");
657 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
658 errmsg(
"invalid input syntax for type %s",
"json"),
676 const char *context_start;
677 const char *context_end;
678 const char *line_start;
686 context_start = line_start;
688 Assert(context_end >= context_start);
691 while (context_end - context_start >= 50)
695 context_start +=
pg_mblen(context_start);
705 if (context_start - line_start <= 3)
706 context_start = line_start;
709 ctxtlen = context_end - context_start;
710 ctxt =
palloc(ctxtlen + 1);
711 memcpy(ctxt, context_start, ctxtlen);
712 ctxt[ctxtlen] =
'\0';
718 prefix = (context_start > line_start) ?
"..." :
"";
721 *context_end !=
'\n' && *context_end !=
'\r') ?
"..." :
"";
723 return errcontext(
"JSON data, line %d: %s%s%s",
748 state->result_size = 256;
749 state->result_count = 0;
750 state->sent_count = 0;
774 char *nxt =
state->result[
state->sent_count++];
795 _state->
result = (
char **)
813 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
814 errmsg(
"cannot call %s on an array",
815 "json_object_keys")));
828 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
829 errmsg(
"cannot call %s on a scalar",
830 "json_object_keys")));
850 result =
get_worker(json, &fnamestr, NULL, 1,
false);
888 result =
get_worker(json, &fnamestr, NULL, 1,
true);
1045 tpath =
palloc(npath *
sizeof(
char *));
1046 ipath =
palloc(npath *
sizeof(
int));
1048 for (
i = 0;
i < npath;
i++)
1058 if (*tpath[
i] !=
'\0')
1065 if (endptr == tpath[
i] || *endptr !=
'\0' || errno != 0)
1074 result =
get_worker(json, tpath, ipath, npath, as_text);
1104 bool normalize_results)
1114 state->normalize_results = normalize_results;
1115 state->npath = npath;
1116 state->path_names = tpath;
1117 state->path_indexes = ipath;
1119 state->array_cur_index =
palloc(
sizeof(
int) * npath);
1122 state->pathok[0] =
true;
1153 return state->tresult;
1162 if (lex_level == 0 && _state->
npath == 0)
1181 if (lex_level == 0 && _state->
npath == 0)
1197 bool get_next =
false;
1200 if (lex_level <= _state->npath &&
1201 _state->
pathok[lex_level - 1] &&
1204 strcmp(fname, _state->
path_names[lex_level - 1]) == 0)
1206 if (lex_level < _state->npath)
1209 _state->
pathok[lex_level] =
true;
1244 bool get_last =
false;
1248 if (lex_level <= _state->npath &&
1249 _state->
pathok[lex_level - 1] &&
1252 strcmp(fname, _state->
path_names[lex_level - 1]) == 0)
1254 if (lex_level < _state->npath)
1257 _state->
pathok[lex_level] =
false;
1297 if (lex_level < _state->npath)
1318 else if (lex_level == 0 && _state->
npath == 0)
1337 if (lex_level == 0 && _state->
npath == 0)
1353 bool get_next =
false;
1357 if (lex_level <= _state->npath)
1360 if (lex_level <= _state->npath &&
1361 _state->
pathok[lex_level - 1] &&
1365 if (lex_level < _state->npath)
1368 _state->
pathok[lex_level] =
true;
1401 bool get_last =
false;
1405 if (lex_level <= _state->npath &&
1406 _state->
pathok[lex_level - 1] &&
1410 if (lex_level < _state->npath)
1413 _state->
pathok[lex_level] =
false;
1448 if (lex_level == 0 && _state->
npath == 0)
1533 bool have_object =
false,
1559 if (npath <= 0 && jbvp == NULL)
1574 for (
i = 0;
i < npath;
i++)
1585 else if (have_array)
1593 lindex =
strtoint(indextext, &endptr, 10);
1594 if (endptr == indextext || *endptr !=
'\0' || errno != 0)
1615 if (lindex == INT_MIN || -lindex > nelements)
1621 index = nelements + lindex;
1638 else if (
i == npath - 1)
1643 container = jbvp->
val.binary.data;
1651 have_object =
false;
1682 bool *path_nulls =
palloc0(path_len *
sizeof(
bool));
1735 for (
int i = level + 1;
i < path_len;
i++)
1751 if (badp ==
c || *badp !=
'\0' || errno != 0)
1755 newkey.
val.string.val =
c;
1756 newkey.
val.string.len = strlen(
c);
1775 if (tpath[(path_len - level) - 1] ==
jbvArray)
1786 for (
int i = path_len - 1;
i > level;
i--)
1810 return v->
val.boolean ?
1881 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1882 errmsg(
"cannot get array length of a scalar")));
1885 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1886 errmsg(
"cannot get array length of a non-array")));
1904 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1905 errmsg(
"cannot get array length of a non-array")));
1918 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1919 errmsg(
"cannot get array length of a scalar")));
1977 bool skipNested =
false;
1984 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1985 errmsg(
"cannot call %s on a non-object",
1992 "jsonb_each temporary cxt",
2005 bool nulls[2] = {
false,
false};
2078 state->normalize_results = as_text;
2079 state->next_scalar =
false;
2082 "json_each temporary cxt",
2125 bool nulls[2] = {
false,
false};
2172 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2173 errmsg(
"cannot deconstruct an array as an object")));
2186 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2187 errmsg(
"cannot deconstruct a scalar")));
2224 bool skipNested =
false;
2231 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2232 errmsg(
"cannot extract elements from a scalar")));
2235 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2236 errmsg(
"cannot extract elements from an object")));
2243 "jsonb_array_elements temporary cxt",
2255 bool nulls[1] = {
false};
2331 state->normalize_results = as_text;
2332 state->next_scalar =
false;
2335 "json_array_elements temporary cxt",
2377 bool nulls[1] = {
false};
2422 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2423 errmsg(
"cannot call %s on a non-array",
2437 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2438 errmsg(
"cannot call %s on a scalar",
2479 false,
true, (
Node *) &escontext);
2488 false,
false, NULL);
2513 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2514 errmsg(
"expected JSON array"),
2518 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2519 errmsg(
"expected JSON array")));
2531 for (
i = 0;
i < ndim;
i++)
2536 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2537 errmsg(
"expected JSON array"),
2538 errhint(
"See the array element %s of key \"%s\".",
2542 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2543 errmsg(
"expected JSON array"),
2544 errhint(
"See the array element %s.",
2575 for (
i = 0;
i < ndims;
i++)
2589 int dim = ctx->
sizes[ndim];
2591 if (ctx->
dims[ndim] == -1)
2592 ctx->
dims[ndim] = dim;
2593 else if (ctx->
dims[ndim] != dim)
2595 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2596 errmsg(
"malformed JSON array"),
2597 errdetail(
"Multidimensional arrays must have "
2598 "sub-arrays with matching dimensions.")));
2601 ctx->
sizes[ndim] = 0;
2605 ctx->
sizes[ndim - 1]++;
2618 bool element_isnull;
2634 ctx->
sizes[ndim - 1]++;
2644 int ndim =
state->lex->lex_level;
2646 if (
state->ctx->ndims <= 0)
2651 else if (ndim < state->ctx->ndims)
2668 int ndim =
state->lex->lex_level;
2670 if (ctx->
ndims <= 0)
2676 if (ndim < ctx->ndims)
2691 int ndim =
state->lex->lex_level;
2693 if (
state->ctx->ndims <= 0 || ndim ==
state->ctx->ndims)
2696 state->element_start =
state->lex->token_start;
2697 state->element_type =
state->lex->token_type;
2698 state->element_scalar = NULL;
2710 int ndim =
state->lex->lex_level;
2714 if (ndim == ctx->
ndims)
2727 else if (
state->element_scalar)
2735 jsv.
val.
json.len = (
state->lex->prev_token_terminator -
2736 state->element_start) *
sizeof(
char);
2753 int ndim =
state->lex->lex_level;
2755 if (ctx->
ndims <= 0)
2760 else if (ndim < ctx->ndims)
2768 if (ndim == ctx->
ndims)
2794 memset(&sem, 0,
sizeof(sem));
2855 if (ctx->
ndims <= 0 &&
2912 const char *colname,
2990 "populate_composite",
3011 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3013 ?
errmsg(
"cannot call %s on a scalar",
3014 "populate_composite")
3015 :
errmsg(
"cannot call %s on an array",
3016 "populate_composite")));
3056 const char *colname,
3084 defaultval, mcxt, &jso, escontext);
3101 if (typid != io->
base_typid && typid != RECORDOID)
3122 bool *isnull,
Node *escontext)
3145 if ((typid == JSONOID || typid == JSONBOID) &&
3162 if (typid == JSONBOID)
3188 jbv->
val.binary.len);
3190 elog(
ERROR,
"unrecognized jsonb type: %d", (
int) jbv->
type);
3210 const char *colname,
3225 jsv, isnull, escontext);
3250 column->
typid = typid;
3255 elog(
ERROR,
"cache lookup failed for type %u", typid);
3259 if (
type->typtype == TYPTYPE_DOMAIN)
3266 int32 base_typmod = typmod;
3290 else if (
type->typtype == TYPTYPE_COMPOSITE || typid == RECORDOID)
3299 else if (IsTrueArrayType(
type))
3331 const char *colname,
3388 jsv, isnull, escontext);
3391 elog(
ERROR,
"unrecognized type category '%c'", typcat);
3405 data->record_typmod = 0;
3406 data->ncolumns = ncolumns;
3427 return hashentry != NULL;
3452 int ncolumns = tupdesc->
natts;
3464 if (record == NULL ||
3480 nulls = (
bool *)
palloc(ncolumns *
sizeof(
bool));
3490 tuple.
t_data = defaultval;
3497 for (
i = 0;
i < ncolumns; ++
i)
3504 for (
i = 0;
i < ncolumns; ++
i)
3507 char *colname =
NameStr(att->attname);
3512 if (att->attisdropped)
3528 if (defaultval && !found)
3567 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3569 errmsg(
"first argument of %s must be a row type",
3591 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3593 errmsg(
"could not determine row type for result of %s",
3595 errhint(
"Provide a non-null record argument, "
3596 "or call the function in the FROM clause "
3597 "using a column definition list.")));
3620 bool is_json,
bool have_record_arg,
3623 int json_arg_num = have_record_arg ? 1 : 0;
3643 if (have_record_arg)
3650 if (!have_record_arg)
3660 if (cache->
argtype == RECORDOID)
3674 if (cache->
argtype == RECORDOID)
3710 jbv.
val.binary.data = &jb->
root;
3716 NULL, fnmcxt, rec, &jsv, &isnull,
3856 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3869 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3962 bool is_json,
bool have_record_arg)
3964 int json_arg_num = have_record_arg ? 1 : 0;
3975 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3976 errmsg(
"set-valued function called in context that cannot accept a set")));
3980 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3981 errmsg(
"materialize mode required, but it is not allowed in this context")));
3996 if (have_record_arg)
4003 if (!have_record_arg)
4013 if (cache->
argtype == RECORDOID)
4027 if (cache->
argtype == RECORDOID)
4055 state->cache = cache;
4089 bool skipNested =
false;
4094 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4095 errmsg(
"cannot call %s on a non-array",
4111 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4112 errmsg(
"argument of %s must be an array of objects",
4144 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4145 errmsg(
"cannot call %s on an object",
4195 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4196 errmsg(
"argument of %s must be an array of objects",
4216 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4217 errmsg(
"cannot call %s on a scalar",
4426 state->skip_next_null =
false;
4440 state->strval->len));
4456 bool last_was_key =
false;
4471 last_was_key =
true;
4478 last_was_key =
false;
4572 bool skipNested =
false;
4577 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4578 errmsg(
"cannot delete from scalar")));
4591 memcmp(keyptr, v.
val.string.val, keylen) == 0))
4626 bool skipNested =
false;
4631 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
4632 errmsg(
"wrong number of array subscripts")));
4636 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4637 errmsg(
"cannot delete from scalar")));
4658 for (
i = 0;
i < keys_len;
i++)
4669 if (keylen == v.
val.string.len &&
4670 memcmp(keyptr, v.
val.string.val, keylen) == 0)
4716 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4717 errmsg(
"cannot delete from scalar")));
4721 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4722 errmsg(
"cannot delete from object using integer index")));
4731 n = v.
val.array.nElems;
4784 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
4785 errmsg(
"wrong number of array subscripts")));
4789 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4790 errmsg(
"cannot set path in scalar")));
4802 res =
setPath(&it, path_elems, path_nulls, path_len, &st,
4830 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4831 errmsg(
"null_value_treatment must be \"delete_key\", \"return_target\", \"use_json_null\", or \"raise_exception\"")));
4840 if (strcmp(handle_val,
"raise_exception") == 0)
4843 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4844 errmsg(
"JSON value must not be null"),
4845 errdetail(
"Exception was raised because null_value_treatment is \"raise_exception\"."),
4846 errhint(
"To avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not passed.")));
4849 else if (strcmp(handle_val,
"use_json_null") == 0)
4855 fcinfo->args[2].value =
newval;
4856 fcinfo->args[2].isnull =
false;
4859 else if (strcmp(handle_val,
"delete_key") == 0)
4863 else if (strcmp(handle_val,
"return_target") == 0)
4872 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4873 errmsg(
"null_value_treatment must be \"delete_key\", \"return_target\", \"use_json_null\", or \"raise_exception\"")));
4895 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
4896 errmsg(
"wrong number of array subscripts")));
4900 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4901 errmsg(
"cannot delete path in scalar")));
4913 res =
setPath(&it, path_elems, path_nulls, path_len, &st,
4943 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
4944 errmsg(
"wrong number of array subscripts")));
4948 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4949 errmsg(
"cannot set path in scalar")));
5103 bool *path_nulls,
int path_len,
5112 if (path_nulls[level])
5114 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5115 errmsg(
"path element at position %d is null",
5131 v.
val.array.rawScalar)
5133 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5134 errmsg(
"cannot replace existing key"),
5135 errdetail(
"The path assumes key is a composite object, "
5136 "but it is a scalar value.")));
5139 setPathArray(it, path_elems, path_nulls, path_len, st, level,
5147 setPathObject(it, path_elems, path_nulls, path_len, st, level,
5164 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5165 errmsg(
"cannot replace existing key"),
5166 errdetail(
"The path assumes key is a composite object, "
5167 "but it is a scalar value.")));
5172 elog(
ERROR,
"unrecognized iterator result: %d", (
int) r);
5188 text *pathelem = NULL;
5194 if (level >= path_len || path_nulls[level])
5204 (level == path_len - 1))
5216 for (
i = 0;
i < npairs;
i++)
5225 k.
val.string.len) == 0)
5229 if (level == path_len - 1)
5237 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5238 errmsg(
"cannot replace existing key"),
5239 errhint(
"Try using the function jsonb_set "
5240 "to replace key value.")));
5252 setPath(it, path_elems, path_nulls, path_len,
5253 st, level + 1,
newval, op_type);
5259 level == path_len - 1 &&
i == npairs - 1)
5276 int walking_level = 1;
5278 while (walking_level != 0)
5312 (void)
push_path(st, level, path_elems, path_nulls,
5333 if (level < path_len && !path_nulls[level])
5340 if (badp ==
c || *badp !=
'\0' || errno != 0)
5342 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
5343 errmsg(
"path element at position %d is not an integer: \"%s\"",
5359 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5360 errmsg(
"path element at position %d is out of range: %d",
5375 if (
idx > 0 &&
idx > nelems)
5384 if ((
idx == INT_MIN || nelems == 0) && (level == path_len - 1) &&
5398 for (
i = 0;
i < nelems;
i++)
5402 if (
i ==
idx && level < path_len)
5406 if (level == path_len - 1)
5425 (
void)
setPath(it, path_elems, path_nulls, path_len,
5426 st, level + 1,
newval, op_type);
5436 int walking_level = 1;
5438 while (walking_level != 0)
5481 (void)
push_path(st, level, path_elems, path_nulls,
5512 errmsg(
"wrong flag type, only arrays and scalars are allowed")));
5518 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5519 errmsg(
"flag array element is not a string"),
5520 errhint(
"Possible values are: \"string\", \"numeric\", \"boolean\", \"key\", and \"all\".")));
5522 if (v.
val.string.len == 3 &&
5525 else if (v.
val.string.len == 3 &&
5528 else if (v.
val.string.len == 6 &&
5531 else if (v.
val.string.len == 7 &&
5534 else if (v.
val.string.len == 7 &&
5539 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5540 errmsg(
"wrong flag in flag array: \"%s\"",
5542 errhint(
"Possible values are: \"string\", \"numeric\", \"boolean\", \"key\", and \"all\".")));
5547 elog(
ERROR,
"unexpected end of flag array");
5552 elog(
ERROR,
"unexpected end of flag array");
5639 state->action_state = action_state;
5640 state->flags = flags;
5713 bool is_scalar =
false;
5722 out = transform_action(action_state, v.
val.string.val, v.
val.string.len);
5738 res->val.array.rawScalar = is_scalar;
5760 state->action = transform_action;
5761 state->action_state = action_state;
5910 *outfuncoid = F_BOOLOUT;
5925 *outfuncoid = F_DATE_OUT;
5930 *outfuncoid = F_TIMESTAMP_OUT;
5934 case TIMESTAMPTZOID:
5935 *outfuncoid = F_TIMESTAMPTZ_OUT;
5952 || typoid == ANYCOMPATIBLEARRAYOID || typoid == RECORDARRAYOID)
5954 *outfuncoid = F_ARRAY_OUT;
5959 *outfuncoid = F_RECORD_OUT;
5980 *outfuncoid = castfunc;
Datum idx(PG_FUNCTION_ARGS)
#define PG_GETARG_ARRAYTYPE_P(n)
bool array_contains_nulls(ArrayType *array)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
Datum makeMdArrayResult(ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Datum numeric_out(PG_FUNCTION_ARGS)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define TextDatumGetCString(d)
#define IS_HIGHBIT_SET(ch)
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
#define OidIsValid(objectId)
static void PGresult * res
bool domain_check_safe(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt, Node *escontext)
void hash_destroy(HTAB *hashp)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int errdetail_internal(const char *fmt,...)
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 HeapTupleHeaderGetDatum(HeapTupleHeader tuple)
@ SFRM_Materialize_Random
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
bool InputFunctionCallSafe(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod, fmNodePtr escontext, Datum *result)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
#define PG_GETARG_TEXT_PP(n)
#define DatumGetHeapTupleHeader(X)
#define DatumGetTextPP(X)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_HEAPTUPLEHEADER(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_GETARG_TEXT_P(n)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
#define SRF_RETURN_DONE(_funcctx)
#define MAT_SRF_USE_EXPECTED_DESC
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
#define HeapTupleIsValid(tuple)
#define HeapTupleHeaderGetTypMod(tup)
#define HeapTupleHeaderGetTypeId(tup)
#define HeapTupleHeaderGetDatumLength(tup)
if(TABLE==NULL||TABLE_index==NULL)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
void escape_json(StringInfo buf, const char *str)
char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
JsonParseErrorType pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
JsonParseErrorType json_lex(JsonLexContext *lex)
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, char *json, int len, int encoding, bool need_escapes)
JsonParseErrorType json_count_array_elements(JsonLexContext *lex, int *elements)
void freeJsonLexContext(JsonLexContext *lex)
@ JSON_UNICODE_CODE_POINT_ZERO
@ JSON_UNICODE_UNTRANSLATABLE
@ JSON_UNICODE_HIGH_ESCAPE
@ JSON_TOKEN_OBJECT_START
Datum jsonb_in(PG_FUNCTION_ARGS)
char * JsonbToCStringIndent(StringInfo out, JsonbContainer *in, int estimated_len)
char * JsonbToCString(StringInfo out, JsonbContainer *in, int estimated_len)
#define JsonContainerIsScalar(jc)
#define JsonContainerIsArray(jc)
#define JsonContainerSize(jc)
#define JB_ROOT_IS_OBJECT(jbp_)
static Datum JsonbPGetDatum(const Jsonb *p)
#define IsAJsonbScalar(jsonbval)
#define PG_RETURN_JSONB_P(x)
#define JB_ROOT_IS_ARRAY(jbp_)
#define PG_GETARG_JSONB_P(x)
#define JsonContainerIsObject(jc)
#define JB_ROOT_IS_SCALAR(jbp_)
#define JB_ROOT_COUNT(jbp_)
JsonbIterator * JsonbIteratorInit(JsonbContainer *container)
Jsonb * JsonbValueToJsonb(JsonbValue *val)
JsonbValue * getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)
JsonbValue * getKeyJsonValueFromContainer(JsonbContainer *container, const char *keyVal, int keyLen, JsonbValue *res)
void JsonbToJsonbValue(Jsonb *jsonb, JsonbValue *val)
JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val, bool skipNested)
JsonbValue * pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq, JsonbValue *jbval)
Datum jsonb_populate_recordset(PG_FUNCTION_ARGS)
static JsonParseErrorType get_array_element_end(void *state, bool isnull)
static Datum elements_worker(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
static JsonParseErrorType hash_array_start(void *state)
Datum jsonb_object_keys(PG_FUNCTION_ARGS)
static JsonParseErrorType populate_recordset_array_start(void *state)
static JsonParseErrorType transform_string_values_array_start(void *state)
static JsonParseErrorType get_object_field_start(void *state, char *fname, bool isnull)
text * transform_json_string_values(text *json, void *action_state, JsonTransformStringValuesAction transform_action)
static JsonParseErrorType elements_object_start(void *state)
static JsonParseErrorType transform_string_values_object_field_start(void *state, char *fname, bool isnull)
Datum jsonb_array_elements(PG_FUNCTION_ARGS)
static JsonParseErrorType iterate_values_object_field_start(void *state, char *fname, bool isnull)
struct PopulateArrayContext PopulateArrayContext
static JsonbValue * IteratorConcat(JsonbIterator **it1, JsonbIterator **it2, JsonbParseState **state)
Datum json_each_text(PG_FUNCTION_ARGS)
Datum json_populate_recordset(PG_FUNCTION_ARGS)
static JsonParseErrorType populate_array_scalar(void *_state, char *token, JsonTokenType tokentype)
Datum jsonb_delete(PG_FUNCTION_ARGS)
Jsonb * transform_jsonb_string_values(Jsonb *jsonb, void *action_state, JsonTransformStringValuesAction transform_action)
struct TransformJsonStringValuesState TransformJsonStringValuesState
Datum jsonb_delete_array(PG_FUNCTION_ARGS)
static JsonbValue * setPath(JsonbIterator **it, Datum *path_elems, bool *path_nulls, int path_len, JsonbParseState **st, int level, JsonbValue *newval, int op_type)
Datum jsonb_pretty(PG_FUNCTION_ARGS)
struct DomainIOData DomainIOData
static JsonParseErrorType transform_string_values_array_end(void *state)
JsonLexContext * makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes)
static JsonParseErrorType populate_recordset_object_start(void *state)
static RecordIOData * allocate_record_info(MemoryContext mcxt, int ncolumns)
static JsonParseErrorType iterate_values_scalar(void *state, char *token, JsonTokenType tokentype)
static text * JsonbValueAsText(JsonbValue *v)
Datum jsonb_insert(PG_FUNCTION_ARGS)
static JsonParseErrorType get_object_start(void *state)
static JsonParseErrorType populate_recordset_object_field_start(void *state, char *fname, bool isnull)
static JsonParseErrorType populate_recordset_object_field_end(void *state, char *fname, bool isnull)
static JsonParseErrorType populate_array_object_start(void *_state)
#define JsObjectIsEmpty(jso)
static void get_record_type_from_argument(FunctionCallInfo fcinfo, const char *funcname, PopulateRecordCache *cache)
Datum json_array_element(PG_FUNCTION_ARGS)
Datum jsonb_delete_idx(PG_FUNCTION_ARGS)
static JsonParseErrorType sn_object_end(void *state)
#define JB_PATH_CREATE_OR_INSERT
Datum jsonb_populate_record_valid(PG_FUNCTION_ARGS)
Datum json_array_elements_text(PG_FUNCTION_ARGS)
struct EachState EachState
static JsonParseErrorType hash_scalar(void *state, char *token, JsonTokenType tokentype)
static JsonParseErrorType sn_array_element_start(void *state, bool isnull)
static Datum populate_record_worker(FunctionCallInfo fcinfo, const char *funcname, bool is_json, bool have_record_arg, Node *escontext)
struct StripnullState StripnullState
static void setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls, int path_len, JsonbParseState **st, int level, JsonbValue *newval, uint32 nelems, int op_type)
struct IterateJsonStringValuesState IterateJsonStringValuesState
#define JsValueIsString(jsv)
static JsonParseErrorType populate_recordset_object_end(void *state)
Datum jsonb_delete_path(PG_FUNCTION_ARGS)
struct CompositeIOData CompositeIOData
static JsonParseErrorType each_object_field_end(void *state, char *fname, bool isnull)
Datum jsonb_object_field_text(PG_FUNCTION_ARGS)
static Datum each_worker(FunctionCallInfo fcinfo, bool as_text)
static JsonParseErrorType get_array_start(void *state)
static JsonParseErrorType each_scalar(void *state, char *token, JsonTokenType tokentype)
static int report_json_context(JsonLexContext *lex)
Datum json_strip_nulls(PG_FUNCTION_ARGS)
static void push_path(JsonbParseState **st, int level, Datum *path_elems, bool *path_nulls, int path_len, JsonbValue *newval)
struct JsonHashEntry JsonHashEntry
Datum jsonb_set_element(Jsonb *jb, Datum *path, int path_len, JsonbValue *newval)
Datum json_array_elements(PG_FUNCTION_ARGS)
Datum jsonb_concat(PG_FUNCTION_ARGS)
static bool populate_array_json(PopulateArrayContext *ctx, char *json, int len)
struct ArrayIOData ArrayIOData
static JsonParseErrorType okeys_array_start(void *state)
Datum json_object_field_text(PG_FUNCTION_ARGS)
uint32 parse_jsonb_index_flags(Jsonb *jb)
Datum jsonb_extract_path_text(PG_FUNCTION_ARGS)
Datum json_each(PG_FUNCTION_ARGS)
static JsonParseErrorType alen_scalar(void *state, char *token, JsonTokenType tokentype)
static JsonParseErrorType sn_object_start(void *state)
static JsonParseErrorType sn_array_start(void *state)
static bool populate_array_check_dimension(PopulateArrayContext *ctx, int ndim)
Datum jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text)
static Datum each_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
static JsonParseErrorType sn_array_end(void *state)
static Datum populate_scalar(ScalarIOData *io, Oid typid, int32 typmod, JsValue *jsv, bool *isnull, Node *escontext)
Datum json_to_recordset(PG_FUNCTION_ARGS)
static JsonParseErrorType get_scalar(void *state, char *token, JsonTokenType tokentype)
static Datum populate_record_field(ColumnIOData *col, Oid typid, int32 typmod, const char *colname, MemoryContext mcxt, Datum defaultval, JsValue *jsv, bool *isnull, Node *escontext)
#define JB_PATH_CONSISTENT_POSITION
static bool populate_array_assign_ndims(PopulateArrayContext *ctx, int ndims)
JsonTokenType json_get_first_token(text *json, bool throw_error)
Datum jsonb_set(PG_FUNCTION_ARGS)
#define JsValueIsNull(jsv)
static void update_cached_tupdesc(CompositeIOData *io, MemoryContext mcxt)
struct ColumnIOData ColumnIOData
void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state, JsonIterateStringValuesAction action)
static JsonParseErrorType populate_array_element_end(void *_state, bool isnull)
Datum jsonb_set_lax(PG_FUNCTION_ARGS)
static JsonParseErrorType elements_array_element_end(void *state, bool isnull)
static JsonParseErrorType sn_object_field_start(void *state, char *fname, bool isnull)
Datum jsonb_each_text(PG_FUNCTION_ARGS)
bool pg_parse_json_or_errsave(JsonLexContext *lex, JsonSemAction *sem, Node *escontext)
static JsonParseErrorType elements_scalar(void *state, char *token, JsonTokenType tokentype)
struct ScalarIOData ScalarIOData
static JsonParseErrorType each_object_field_start(void *state, char *fname, bool isnull)
Datum jsonb_strip_nulls(PG_FUNCTION_ARGS)
struct OkeysState OkeysState
struct PopulateArrayState PopulateArrayState
struct PopulateRecordCache PopulateRecordCache
Datum jsonb_extract_path(PG_FUNCTION_ARGS)
static void push_null_elements(JsonbParseState **ps, int num)
void json_categorize_type(Oid typoid, bool is_jsonb, JsonTypeCategory *tcategory, Oid *outfuncoid)
static Datum populate_array(ArrayIOData *aio, const char *colname, MemoryContext mcxt, JsValue *jsv, bool *isnull, Node *escontext)
static JsonParseErrorType okeys_object_field_start(void *state, char *fname, bool isnull)
static Datum populate_domain(DomainIOData *io, Oid typid, const char *colname, MemoryContext mcxt, JsValue *jsv, bool *isnull, Node *escontext)
Datum json_array_length(PG_FUNCTION_ARGS)
struct JHashState JHashState
void json_errsave_error(JsonParseErrorType error, JsonLexContext *lex, Node *escontext)
struct ElementsState ElementsState
Datum jsonb_array_length(PG_FUNCTION_ARGS)
Datum jsonb_object_field(PG_FUNCTION_ARGS)
static Datum elements_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
void iterate_json_values(text *json, uint32 flags, void *action_state, JsonIterateStringValuesAction action)
Datum jsonb_populate_record(PG_FUNCTION_ARGS)
Datum json_extract_path(PG_FUNCTION_ARGS)
Datum json_extract_path_text(PG_FUNCTION_ARGS)
static JsonParseErrorType elements_array_element_start(void *state, bool isnull)
static void get_record_type_from_query(FunctionCallInfo fcinfo, const char *funcname, PopulateRecordCache *cache)
Datum json_populate_record(PG_FUNCTION_ARGS)
static JsonParseErrorType populate_recordset_array_element_start(void *state, bool isnull)
#define JB_PATH_FILL_GAPS
static JsonParseErrorType transform_string_values_object_end(void *state)
static bool JsValueToJsObject(JsValue *jsv, JsObject *jso, Node *escontext)
Datum json_object_field(PG_FUNCTION_ARGS)
static JsonParseErrorType okeys_scalar(void *state, char *token, JsonTokenType tokentype)
static Datum get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
static void populate_array_report_expected_array(PopulateArrayContext *ctx, int ndim)
static JsonParseErrorType get_object_end(void *state)
static Datum populate_composite(CompositeIOData *io, Oid typid, const char *colname, MemoryContext mcxt, HeapTupleHeader defaultval, JsValue *jsv, bool *isnull, Node *escontext)
Datum jsonb_to_record(PG_FUNCTION_ARGS)
Datum jsonb_array_element(PG_FUNCTION_ARGS)
static HTAB * get_json_object_as_hash(char *json, int len, const char *funcname, Node *escontext)
Datum json_object_keys(PG_FUNCTION_ARGS)
struct AlenState AlenState
#define JB_PATH_INSERT_BEFORE
static JsonParseErrorType populate_recordset_scalar(void *state, char *token, JsonTokenType tokentype)
static JsonParseErrorType get_object_field_end(void *state, char *fname, bool isnull)
static Datum get_path_all(FunctionCallInfo fcinfo, bool as_text)
static Datum populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname, bool is_json, bool have_record_arg)
static HeapTupleHeader populate_record(TupleDesc tupdesc, RecordIOData **record_p, HeapTupleHeader defaultval, MemoryContext mcxt, JsObject *obj, Node *escontext)
static JsonParseErrorType alen_object_start(void *state)
static bool JsObjectGetField(JsObject *obj, char *field, JsValue *jsv)
static bool populate_array_element(PopulateArrayContext *ctx, int ndim, JsValue *jsv)
static JsonParseErrorType populate_array_element_start(void *_state, bool isnull)
static JsonParseErrorType populate_array_array_end(void *_state)
static void prepare_column_cache(ColumnIOData *column, Oid typid, int32 typmod, MemoryContext mcxt, bool need_scalar)
static JsonParseErrorType get_array_end(void *state)
Datum jsonb_to_recordset(PG_FUNCTION_ARGS)
static JsonParseErrorType sn_scalar(void *state, char *token, JsonTokenType tokentype)
#define JB_PATH_INSERT_AFTER
Datum jsonb_each(PG_FUNCTION_ARGS)
static JsonParseErrorType get_array_element_start(void *state, bool isnull)
static JsonParseErrorType hash_object_field_end(void *state, char *fname, bool isnull)
static void populate_recordset_record(PopulateRecordsetState *state, JsObject *obj)
#define JsObjectFree(jso)
struct PopulateRecordsetState PopulateRecordsetState
static JsonParseErrorType transform_string_values_object_start(void *state)
static JsonParseErrorType transform_string_values_array_element_start(void *state, bool isnull)
static JsonParseErrorType alen_array_element_start(void *state, bool isnull)
static bool populate_array_dim_jsonb(PopulateArrayContext *ctx, JsonbValue *jbv, int ndim)
Datum jsonb_array_element_text(PG_FUNCTION_ARGS)
@ TYPECAT_COMPOSITE_DOMAIN
Datum json_to_record(PG_FUNCTION_ARGS)
static JsonParseErrorType each_array_start(void *state)
Datum json_array_element_text(PG_FUNCTION_ARGS)
static void setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls, int path_len, JsonbParseState **st, int level, JsonbValue *newval, uint32 npairs, int op_type)
static JsonParseErrorType transform_string_values_scalar(void *state, char *token, JsonTokenType tokentype)
static JsonParseErrorType hash_object_field_start(void *state, char *fname, bool isnull)
Datum jsonb_array_elements_text(PG_FUNCTION_ARGS)
static text * get_worker(text *json, char **tpath, int *ipath, int npath, bool normalize_results)
#define pg_parse_json_or_ereport(lex, sem)
void(* JsonIterateStringValuesAction)(void *state, char *elem_value, int elem_len)
text *(* JsonTransformStringValuesAction)(void *state, char *elem_value, int elem_len)
Assert(fmt[strlen(fmt) - 1] !='\n')
Oid get_element_type(Oid typid)
bool type_is_rowtype(Oid typid)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
char get_typtype(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Oid getBaseType(Oid typid)
int GetDatabaseEncoding(void)
int pg_mblen(const char *mbstr)
char * pnstrdup(const char *in, Size len)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
void * MemoryContextAllocZero(MemoryContext context, Size size)
MemoryContext CurrentMemoryContext
void * repalloc(void *pointer, Size size)
void * MemoryContextAlloc(MemoryContext context, Size size)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define SOFT_ERROR_OCCURRED(escontext)
#define IsA(nodeptr, _type_)
static Datum NumericGetDatum(Numeric X)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
FormData_pg_attribute * Form_pg_attribute
FormData_pg_type * Form_pg_type
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
void check_stack_depth(void)
static Datum PointerGetDatum(const void *X)
static char * DatumGetCString(Datum X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
static chr element(struct vars *v, const chr *startp, const chr *endp)
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
StringInfo makeStringInfo(void)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
#define appendStringInfoCharMacro(str, ch)
ColumnIOData * element_info
CompositeIOData composite
union ColumnIOData::@23 io
Tuplestorestate * tuple_store
Tuplestorestate * tuple_store
const char * function_name
MemoryContext ecxt_per_query_memory
MemoryContext multi_call_memory_ctx
JsonIterateStringValuesAction action
const char * function_name
JsonTokenType saved_token_type
JsonbContainer * jsonb_cont
struct JsValue::@24::@25 json
char * prev_token_terminator
json_struct_action array_end
json_struct_action object_start
json_ofield_action object_field_start
json_aelem_action array_element_start
json_scalar_action scalar
json_aelem_action array_element_end
json_struct_action array_start
json_struct_action object_end
json_ofield_action object_field_end
JsonTokenType element_type
PopulateArrayContext * ctx
const char * function_name
Tuplestorestate * tuple_store
PopulateRecordCache * cache
JsonTokenType saved_token_type
ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER]
SetFunctionReturnMode returnMode
Tuplestorestate * setResult
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define FirstNormalObjectId
void FreeTupleDesc(TupleDesc tupdesc)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
#define ReleaseTupleDesc(tupdesc)
#define TupleDescAttr(tupdesc, i)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
#define VARSIZE_ANY_EXHDR(PTR)
char * text_to_cstring(const text *t)
text * cstring_to_text_with_len(const char *s, int len)
text * cstring_to_text(const char *s)