35#include "utils/fmgroids.h"
47#define JB_PATH_CREATE 0x0001
48#define JB_PATH_DELETE 0x0002
49#define JB_PATH_REPLACE 0x0004
50#define JB_PATH_INSERT_BEFORE 0x0008
51#define JB_PATH_INSERT_AFTER 0x0010
52#define JB_PATH_CREATE_OR_INSERT \
53 (JB_PATH_INSERT_BEFORE | JB_PATH_INSERT_AFTER | JB_PATH_CREATE)
54#define JB_PATH_FILL_GAPS 0x0020
55#define JB_PATH_CONSISTENT_POSITION 0x0040
323#define JsValueIsNull(jsv) \
325 (!(jsv)->val.json.str || (jsv)->val.json.type == JSON_TOKEN_NULL) : \
326 (!(jsv)->val.jsonb || (jsv)->val.jsonb->type == jbvNull))
328#define JsValueIsString(jsv) \
329 ((jsv)->is_json ? (jsv)->val.json.type == JSON_TOKEN_STRING \
330 : ((jsv)->val.jsonb && (jsv)->val.jsonb->type == jbvString))
332#define JsObjectIsEmpty(jso) \
334 ? hash_get_num_entries((jso)->val.json_hash) == 0 \
335 : ((jso)->val.jsonb_cont == NULL || \
336 JsonContainerSize((jso)->val.jsonb_cont) == 0))
338#define JsObjectFree(jso) \
340 if ((jso)->is_json) \
341 hash_destroy((jso)->val.json_hash); \
365 bool normalize_results);
455 bool *isnull,
Node *escontext,
bool omit_quotes);
478 Node *escontext,
bool omit_quotes);
588 errmsg(
"cannot call %s on a scalar",
589 "jsonb_object_keys")));
593 errmsg(
"cannot call %s on an array",
594 "jsonb_object_keys")));
602 state->result_count = 0;
603 state->sent_count = 0;
652 errmsg(
"unsupported Unicode escape sequence"),
659 elog(
ERROR,
"JSON semantic action function did not provide error information");
664 errmsg(
"invalid input syntax for type %s",
"json"),
684 const char *line_start;
729 return errcontext(
"JSON data, line %d: %s%s%s",
754 state->result_size = 256;
755 state->result_count = 0;
756 state->sent_count = 0;
794 if (
_state->lex->lex_level != 1)
801 _state->result = (
char **)
817 if (
_state->lex->lex_level == 0)
820 errmsg(
"cannot call %s on an array",
821 "json_object_keys")));
832 if (
_state->lex->lex_level == 0)
835 errmsg(
"cannot call %s on a scalar",
836 "json_object_keys")));
1054 for (
i = 0;
i < npath;
i++)
1071 if (endptr ==
tpath[
i] || *endptr !=
'\0' ||
errno != 0)
1110 bool normalize_results)
1120 state->normalize_results = normalize_results;
1121 state->npath = npath;
1128 state->pathok[0] =
true;
1159 return state->tresult;
1166 int lex_level =
_state->lex->lex_level;
1168 if (lex_level == 0 &&
_state->npath == 0)
1185 int lex_level =
_state->lex->lex_level;
1187 if (lex_level == 0 &&
_state->npath == 0)
1204 int lex_level =
_state->lex->lex_level;
1207 _state->pathok[lex_level - 1] &&
1215 _state->pathok[lex_level] =
true;
1230 if (
_state->normalize_results &&
1234 _state->next_scalar =
true;
1251 int lex_level =
_state->lex->lex_level;
1255 _state->pathok[lex_level - 1] &&
1263 _state->pathok[lex_level] =
false;
1280 if (isnull &&
_state->normalize_results)
1301 int lex_level =
_state->lex->lex_level;
1306 _state->array_cur_index[lex_level] = -1;
1309 if (
_state->path_indexes[lex_level] < 0 &&
1320 if (-
_state->path_indexes[lex_level] <= nelements)
1321 _state->path_indexes[lex_level] += nelements;
1324 else if (lex_level == 0 &&
_state->npath == 0)
1341 int lex_level =
_state->lex->lex_level;
1343 if (lex_level == 0 &&
_state->npath == 0)
1360 int lex_level =
_state->lex->lex_level;
1364 _state->array_cur_index[lex_level - 1]++;
1367 _state->pathok[lex_level - 1] &&
1369 _state->array_cur_index[lex_level - 1] ==
_state->path_indexes[lex_level - 1])
1374 _state->pathok[lex_level] =
true;
1389 if (
_state->normalize_results &&
1392 _state->next_scalar =
true;
1408 int lex_level =
_state->lex->lex_level;
1412 _state->pathok[lex_level - 1] &&
1414 _state->array_cur_index[lex_level - 1] ==
_state->path_indexes[lex_level - 1])
1419 _state->pathok[lex_level] =
false;
1431 if (isnull &&
_state->normalize_results)
1451 int lex_level =
_state->lex->lex_level;
1454 if (lex_level == 0 &&
_state->npath == 0)
1459 _state->next_scalar =
true;
1484 _state->next_scalar =
false;
1580 for (
i = 0;
i < npath;
i++)
1644 else if (
i == npath - 1)
1649 container =
jbvp->val.binary.data;
1813 return v->
val.boolean ?
1885 errmsg(
"cannot get array length of a scalar")));
1889 errmsg(
"cannot get array length of a non-array")));
1905 if (
_state->lex->lex_level == 0)
1908 errmsg(
"cannot get array length of a non-array")));
1919 if (
_state->lex->lex_level == 0)
1922 errmsg(
"cannot get array length of a scalar")));
1933 if (
_state->lex->lex_level == 1)
1988 errmsg(
"cannot call %s on a non-object",
1995 "jsonb_each temporary cxt",
2008 bool nulls[2] = {
false,
false};
2082 state->next_scalar =
false;
2085 "json_each temporary cxt",
2103 if (
_state->lex->lex_level == 1)
2111 _state->next_scalar =
true;
2128 bool nulls[2] = {
false,
false};
2131 if (
_state->lex->lex_level != 1)
2139 if (isnull &&
_state->normalize_results)
2144 else if (
_state->next_scalar)
2147 _state->next_scalar =
false;
2173 if (
_state->lex->lex_level == 0)
2176 errmsg(
"cannot deconstruct an array as an object")));
2187 if (
_state->lex->lex_level == 0)
2190 errmsg(
"cannot deconstruct a scalar")));
2235 errmsg(
"cannot extract elements from a scalar")));
2239 errmsg(
"cannot extract elements from an object")));
2246 "jsonb_array_elements temporary cxt",
2258 bool nulls[1] = {
false};
2335 state->next_scalar =
false;
2338 "json_array_elements temporary cxt",
2355 if (
_state->lex->lex_level == 1)
2363 _state->next_scalar =
true;
2380 bool nulls[1] = {
false};
2383 if (
_state->lex->lex_level != 1)
2389 if (isnull &&
_state->normalize_results)
2394 else if (
_state->next_scalar)
2397 _state->next_scalar =
false;
2423 if (
_state->lex->lex_level == 0)
2426 errmsg(
"cannot call %s on a non-array",
2427 _state->function_name)));
2438 if (
_state->lex->lex_level == 0)
2441 errmsg(
"cannot call %s on a scalar",
2442 _state->function_name)));
2482 false,
true, (
Node *) &escontext);
2491 false,
false,
NULL);
2517 errmsg(
"expected JSON array"),
2522 errmsg(
"expected JSON array")));
2534 for (
i = 0;
i < ndim;
i++)
2540 errmsg(
"expected JSON array"),
2541 errhint(
"See the array element %s of key \"%s\".",
2546 errmsg(
"expected JSON array"),
2547 errhint(
"See the array element %s.",
2578 for (
i = 0;
i < ndims;
i++)
2592 int dim = ctx->
sizes[ndim];
2594 if (ctx->
dims[ndim] == -1)
2595 ctx->
dims[ndim] = dim;
2596 else if (ctx->
dims[ndim] != dim)
2599 errmsg(
"malformed JSON array"),
2600 errdetail(
"Multidimensional arrays must have "
2601 "sub-arrays with matching dimensions.")));
2604 ctx->
sizes[ndim] = 0;
2608 ctx->
sizes[ndim - 1]++;
2638 ctx->
sizes[ndim - 1]++;
2648 int ndim =
state->lex->lex_level;
2650 if (
state->ctx->ndims <= 0)
2672 int ndim =
state->lex->lex_level;
2674 if (ctx->
ndims <= 0)
2695 int ndim =
state->lex->lex_level;
2697 if (
state->ctx->ndims <= 0 || ndim ==
state->ctx->ndims)
2700 state->element_start =
state->lex->token_start;
2701 state->element_type =
state->lex->token_type;
2714 int ndim =
state->lex->lex_level;
2718 if (ndim == ctx->
ndims)
2723 jsv.val.json.type =
state->element_type;
2729 jsv.val.json.len = 0;
2731 else if (
state->element_scalar)
2733 jsv.val.json.str =
state->element_scalar;
2734 jsv.val.json.len = -1;
2738 jsv.val.json.str =
state->element_start;
2739 jsv.val.json.len = (
state->lex->prev_token_terminator -
2740 state->element_start) *
sizeof(
char);
2757 int ndim =
state->lex->lex_level;
2759 if (ctx->
ndims <= 0)
2772 if (ndim == ctx->
ndims)
2859 if (ctx->
ndims <= 0 &&
2869 jsv.is_json =
false;
2916 const char *colname,
2941 jsv->val.json.len >= 0 ?
jsv->val.json.len
2984 jso->is_json =
jsv->is_json;
2989 jso->val.json_hash =
2991 jsv->val.json.len >= 0
2994 "populate_composite",
3005 jso->val.jsonb_cont =
jbv->val.binary.data;
3017 ?
errmsg(
"cannot call %s on a scalar",
3018 "populate_composite")
3019 :
errmsg(
"cannot call %s on an array",
3020 "populate_composite")));
3060 const char *colname,
3126 bool *isnull,
Node *escontext,
bool omit_quotes)
3130 const char *json =
NULL;
3134 int len =
jsv->val.json.len;
3136 json =
jsv->val.json.str;
3197 jbv->val.binary.len);
3199 elog(
ERROR,
"unrecognized jsonb type: %d", (
int)
jbv->type);
3219 const char *colname,
3235 jsv, isnull, escontext, omit_quotes);
3265 elog(
ERROR,
"cache lookup failed for type %u", typid);
3276 int32 base_typmod = typmod;
3285 column->io.composite.base_typid = base_typid;
3286 column->io.composite.base_typmod = base_typmod;
3293 column->io.domain.base_typid = base_typid;
3294 column->io.domain.base_typmod = base_typmod;
3295 column->io.domain.base_io =
3305 column->io.composite.base_typid = typid;
3306 column->io.composite.base_typmod = typmod;
3314 column->io.array.element_type =
type->typelem;
3316 column->io.array.element_typmod = typmod;
3348 bool *isnull,
bool omit_quotes,
3363 else if (
jsv.is_json)
3385 jbv.val.string.val =
str;
3391 jbv.val.binary.data = &jsonb->
root;
3401 escontext, omit_quotes);
3409 const char *colname,
3425 if (
col->typid != typid ||
col->typmod != typmod)
3430 typcat =
col->typcat;
3470 elog(
ERROR,
"unrecognized type category '%c'", typcat);
3484 data->record_typmod = 0;
3485 data->ncolumns = ncolumns;
3504 jsv->val.json.len =
jsv->val.json.str ? -1 : 0;
3514 return jsv->val.jsonb !=
NULL;
3531 int ncolumns = tupdesc->
natts;
3543 if (record ==
NULL ||
3559 nulls = (
bool *)
palloc(ncolumns *
sizeof(
bool));
3576 for (
i = 0;
i < ncolumns; ++
i)
3583 for (
i = 0;
i < ncolumns; ++
i)
3591 if (
att->attisdropped)
3649 errmsg(
"first argument of %s must be a row type",
3673 errmsg(
"could not determine row type for result of %s",
3675 errhint(
"Provide a non-null record argument, "
3676 "or call the function in the FROM clause "
3677 "using a column definition list.")));
3771 jsv.is_json = is_json;
3790 jbv.val.binary.data = &
jb->root;
3857 if (
_state->lex->lex_level > 1)
3888 if (
_state->lex->lex_level > 1)
3913 int len =
_state->lex->prev_token_terminator -
_state->save_json_start;
3934 if (
_state->lex->lex_level == 0)
3937 errmsg(
"cannot call %s on an array",
_state->function_name)));
3947 if (
_state->lex->lex_level == 0)
3950 errmsg(
"cannot call %s on a scalar",
_state->function_name)));
3952 if (
_state->lex->lex_level == 1)
4056 errmsg(
"set-valued function called in context that cannot accept a set")));
4061 errmsg(
"materialize mode required, but it is not allowed in this context")));
4135 state->cache = cache;
4175 errmsg(
"cannot call %s on a non-array",
4192 errmsg(
"argument of %s must be an array of objects",
4218 int lex_level =
_state->lex->lex_level;
4225 errmsg(
"cannot call %s on an object",
4226 _state->function_name)));
4251 if (
_state->lex->lex_level > 1)
4272 if (
_state->lex->lex_level == 1 &&
4276 errmsg(
"argument of %s must be an array of objects",
4277 _state->function_name)));
4294 if (
_state->lex->lex_level == 0)
4297 errmsg(
"cannot call %s on a scalar",
4298 _state->function_name)));
4300 if (
_state->lex->lex_level == 2)
4311 if (
_state->lex->lex_level > 2)
4339 if (
_state->lex->lex_level > 2)
4364 int len =
_state->lex->prev_token_terminator -
_state->save_json_start;
4441 _state->skip_next_null =
true;
4445 if (
_state->strval->data[
_state->strval->len - 1] !=
'{')
4465 if (isnull &&
_state->strip_in_arrays)
4467 _state->skip_next_null =
true;
4472 if (
_state->strval->len > 0 &&
4486 if (
_state->skip_next_null)
4489 _state->skip_next_null =
false;
4520 state->skip_next_null =
false;
4521 state->strip_in_arrays = strip_in_arrays;
4535 state->strval->len));
4545 bool strip_in_arrays =
false;
4587 if (strip_in_arrays)
4676 errmsg(
"cannot delete from scalar")));
4727 errmsg(
"wrong number of array subscripts")));
4732 errmsg(
"cannot delete from scalar")));
4764 if (keylen == v.
val.string.len &&
4809 errmsg(
"cannot delete from scalar")));
4814 errmsg(
"cannot delete from object using integer index")));
4823 n = v.
val.array.nElems;
4874 errmsg(
"wrong number of array subscripts")));
4879 errmsg(
"cannot set path in scalar")));
4914 errmsg(
"null_value_treatment must be \"delete_key\", \"return_target\", \"use_json_null\", or \"raise_exception\"")));
4927 errmsg(
"JSON value must not be null"),
4928 errdetail(
"Exception was raised because null_value_treatment is \"raise_exception\"."),
4929 errhint(
"To avoid, either change the null_value_treatment argument or ensure that an SQL NULL is not passed.")));
4938 fcinfo->args[2].value =
newval;
4939 fcinfo->args[2].isnull =
false;
4956 errmsg(
"null_value_treatment must be \"delete_key\", \"return_target\", \"use_json_null\", or \"raise_exception\"")));
4978 errmsg(
"wrong number of array subscripts")));
4983 errmsg(
"cannot delete path in scalar")));
5023 errmsg(
"wrong number of array subscripts")));
5028 errmsg(
"cannot set path in scalar")));
5188 errmsg(
"path element at position %d is null",
5204 v.
val.array.rawScalar)
5207 errmsg(
"cannot replace existing key"),
5208 errdetail(
"The path assumes key is a composite object, "
5209 "but it is a scalar value.")));
5238 errmsg(
"cannot replace existing key"),
5239 errdetail(
"The path assumes key is a composite object, "
5240 "but it is a scalar value.")));
5245 elog(
ERROR,
"unrecognized iterator result: %d", (
int) r);
5295 k.
val.string.len) == 0)
5308 errmsg(
"cannot replace existing key"),
5309 errhint(
"Try using the function jsonb_set "
5310 "to replace key value.")));
5412 errmsg(
"path element at position %d is not an integer: \"%s\"",
5429 errmsg(
"path element at position %d is out of range: %d",
5444 if (
idx > 0 &&
idx > nelems)
5467 for (
i = 0;
i < nelems;
i++)
5580 errmsg(
"wrong flag type, only arrays and scalars are allowed")));
5587 errmsg(
"flag array element is not a string"),
5588 errhint(
"Possible values are: \"string\", \"numeric\", \"boolean\", \"key\", and \"all\".")));
5590 if (v.
val.string.len == 3 &&
5593 else if (v.
val.string.len == 3 &&
5596 else if (v.
val.string.len == 6 &&
5599 else if (v.
val.string.len == 7 &&
5602 else if (v.
val.string.len == 7 &&
5608 errmsg(
"wrong flag in flag array: \"%s\"",
5610 errhint(
"Possible values are: \"string\", \"numeric\", \"boolean\", \"key\", and \"all\".")));
5615 elog(
ERROR,
"unexpected end of flag array");
5620 elog(
ERROR,
"unexpected end of flag array");
5648 action(
state, v.
val.string.val, v.
val.string.len);
5663 action(
state, v.
val.string.val, v.
val.string.len);
5681 action(
state,
"true", 4);
5683 action(
state,
"false", 5);
5706 state->action = action;
5707 state->action_state = action_state;
5708 state->flags = flags;
5831 state->action_state = action_state;
5898 if (
_state->strval->data[
_state->strval->len - 1] !=
'{')
5916 if (
_state->strval->data[
_state->strval->len - 1] !=
'[')
6105 for (
int i = 0;
i < tupdesc->
natts;
i++)
6109 if (attr->attisdropped)
Datum idx(PG_FUNCTION_ARGS)
#define PG_GETARG_ARRAYTYPE_P(n)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
bool array_contains_nulls(const ArrayType *array)
Datum makeMdArrayResult(ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
void deconstruct_array_builtin(const 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 unconstify(underlying_type, expr)
#define IS_HIGHBIT_SET(ch)
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
#define OidIsValid(objectId)
bool domain_check_safe(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt, Node *escontext)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
void hash_destroy(HTAB *hashp)
int errcode(int sqlerrcode)
#define ereturn(context, dummy_value,...)
#define errsave(context,...)
int int errdetail_internal(const char *fmt,...) pg_attribute_printf(1
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
Datum HeapTupleHeaderGetDatum(HeapTupleHeader tuple)
@ SFRM_Materialize_Random
#define palloc_object(type)
#define palloc_array(type, count)
#define palloc0_array(type, count)
#define palloc0_object(type)
varlena * pg_detoast_datum_packed(varlena *datum)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
bool InputFunctionCallSafe(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod, Node *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)
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static void * GETSTRUCT(const HeapTupleData *tuple)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
static uint32 pg_abs_s32(int32 a)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
void escape_json_text(StringInfo buf, const text *txt)
void escape_json_with_len(StringInfo buf, const char *str, int len)
void escape_json(StringInfo buf, const char *str)
JsonParseErrorType pg_parse_json(JsonLexContext *lex, const JsonSemAction *sem)
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes)
JsonParseErrorType json_lex(JsonLexContext *lex)
char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
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
char * JsonbUnquote(Jsonb *jb)
Datum jsonb_in(PG_FUNCTION_ARGS)
char * JsonbToCString(StringInfo out, JsonbContainer *in, int estimated_len)
char * JsonbToCStringIndent(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)
static Jsonb * DatumGetJsonbP(Datum d)
#define JB_ROOT_IS_SCALAR(jbp_)
#define JB_ROOT_COUNT(jbp_)
void pushJsonbValue(JsonbInState *pstate, JsonbIteratorToken seq, JsonbValue *jbval)
JsonbValue * getKeyJsonValueFromContainer(JsonbContainer *container, const char *keyVal, int keyLen, JsonbValue *res)
JsonbIterator * JsonbIteratorInit(JsonbContainer *container)
void JsonbToJsonbValue(Jsonb *jsonb, JsonbValue *val)
JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val, bool skipNested)
JsonbValue * getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)
Jsonb * JsonbValueToJsonb(JsonbValue *val)
Datum jsonb_populate_recordset(PG_FUNCTION_ARGS)
JsonLexContext * makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes)
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)
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)
static void IteratorConcat(JsonbIterator **it1, JsonbIterator **it2, JsonbInState *state)
Datum json_each_text(PG_FUNCTION_ARGS)
static void push_path(JsonbInState *st, int level, const Datum *path_elems, const bool *path_nulls, int path_len, JsonbValue *newval)
Datum json_populate_recordset(PG_FUNCTION_ARGS)
void json_check_mutability(Oid typoid, bool is_jsonb, bool *has_mutable)
static JsonParseErrorType populate_array_scalar(void *_state, char *token, JsonTokenType tokentype)
text * transform_json_string_values(text *json, void *action_state, JsonTransformStringValuesAction transform_action)
Datum jsonb_delete(PG_FUNCTION_ARGS)
Datum json_populate_type(Datum json_val, Oid json_type, Oid typid, int32 typmod, void **cache, MemoryContext mcxt, bool *isnull, bool omit_quotes, Node *escontext)
Datum jsonb_delete_array(PG_FUNCTION_ARGS)
Datum jsonb_pretty(PG_FUNCTION_ARGS)
static void setPathArray(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls, int path_len, JsonbInState *st, int level, JsonbValue *newval, uint32 nelems, int op_type)
static JsonParseErrorType transform_string_values_array_end(void *state)
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)
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)
static HTAB * get_json_object_as_hash(const char *json, int len, const char *funcname, Node *escontext)
static bool populate_array_json(PopulateArrayContext *ctx, const char *json, int len)
#define JsValueIsString(jsv)
static JsonParseErrorType populate_recordset_object_end(void *state)
static Datum populate_record_field(ColumnIOData *col, Oid typid, int32 typmod, const char *colname, MemoryContext mcxt, Datum defaultval, JsValue *jsv, bool *isnull, Node *escontext, bool omit_scalar_quotes)
Datum jsonb_delete_path(PG_FUNCTION_ARGS)
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)
Datum json_array_elements(PG_FUNCTION_ARGS)
Datum jsonb_concat(PG_FUNCTION_ARGS)
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)
Datum jsonb_set_element(Jsonb *jb, const Datum *path, int path_len, JsonbValue *newval)
static JsonParseErrorType sn_object_start(void *state)
static JsonParseErrorType sn_array_start(void *state)
static bool populate_array_check_dimension(PopulateArrayContext *ctx, int ndim)
static Datum each_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
static JsonParseErrorType sn_array_end(void *state)
static void setPathObject(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls, int path_len, JsonbInState *st, int level, JsonbValue *newval, uint32 npairs, int op_type)
Datum json_to_recordset(PG_FUNCTION_ARGS)
static JsonParseErrorType get_scalar(void *state, char *token, JsonTokenType tokentype)
#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)
static JsonParseErrorType elements_scalar(void *state, char *token, JsonTokenType tokentype)
static JsonParseErrorType each_object_field_start(void *state, char *fname, bool isnull)
Datum jsonb_strip_nulls(PG_FUNCTION_ARGS)
Datum jsonb_extract_path(PG_FUNCTION_ARGS)
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)
Datum jsonb_get_element(Jsonb *jb, const Datum *path, int npath, bool *isnull, bool as_text)
Datum json_array_length(PG_FUNCTION_ARGS)
void json_errsave_error(JsonParseErrorType error, JsonLexContext *lex, Node *escontext)
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)
static void push_null_elements(JsonbInState *ps, int num)
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
Jsonb * transform_jsonb_string_values(Jsonb *jsonb, void *action_state, JsonTransformStringValuesAction transform_action)
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)
Datum json_object_keys(PG_FUNCTION_ARGS)
#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)
bool pg_parse_json_or_errsave(JsonLexContext *lex, const JsonSemAction *sem, Node *escontext)
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 void setPath(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls, int path_len, JsonbInState *st, int level, JsonbValue *newval, int op_type)
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)
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 Datum populate_scalar(ScalarIOData *io, Oid typid, int32 typmod, JsValue *jsv, bool *isnull, Node *escontext, bool omit_quotes)
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 Datum populate_domain(DomainIOData *io, Oid typid, const char *colname, MemoryContext mcxt, JsValue *jsv, bool *isnull, Node *escontext, bool omit_quotes)
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)
text *(* JsonTransformStringValuesAction)(void *state, char *elem_value, int elem_len)
void(* JsonIterateStringValuesAction)(void *state, char *elem_value, int elem_len)
Oid get_range_subtype(Oid rangeOid)
Oid get_element_type(Oid typid)
bool type_is_rowtype(Oid typid)
Oid get_multirange_range(Oid multirangeOid)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
char func_volatile(Oid funcid)
char get_typtype(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Oid getBaseType(Oid typid)
int GetDatabaseEncoding(void)
int pg_mblen_range(const char *mbstr, const char *end)
void * MemoryContextAlloc(MemoryContext context, Size size)
void MemoryContextReset(MemoryContext context)
void * MemoryContextAllocZero(MemoryContext context, Size size)
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
char * pnstrdup(const char *in, Size len)
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
static char buf[DEFAULT_XLOG_SEG_SIZE]
END_CATALOG_STRUCT typedef FormData_pg_type * Form_pg_type
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
static chr element(struct vars *v, const chr *startp, const chr *endp)
void check_stack_depth(void)
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
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::@26 io
const char * result_start
Tuplestorestate * tuple_store
Tuplestorestate * tuple_store
const char * function_name
const char * result_start
MemoryContext ecxt_per_query_memory
const char * result_start
JsonIterateStringValuesAction action
const char * save_json_start
const char * function_name
JsonTokenType saved_token_type
JsonbContainer * jsonb_cont
struct JsValue::@27::@28 json
const char * 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 * element_start
const char * save_json_start
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(SysCacheIdentifier cacheId, Datum key1)
#define FirstNormalObjectId
void FreeTupleDesc(TupleDesc tupdesc)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
#define ReleaseTupleDesc(tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int 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)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static Size VARSIZE(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
text * cstring_to_text_with_len(const char *s, int len)
text * cstring_to_text(const char *s)
char * text_to_cstring(const text *t)