60 Datum *vals,
bool *nulls,
int *valcount,
67 Oid val_type,
bool key_scalar);
102 elog(
ERROR,
"unsupported jsonb version number %d", version);
197 switch (jbv->
val.datetime.typid)
202 return "time without time zone";
204 return "time with time zone";
206 return "timestamp without time zone";
208 return "timestamp with time zone";
210 elog(
ERROR,
"unrecognized jsonb value datetime type: %d",
211 jbv->
val.datetime.typid);
250 memset(&sem, 0,
sizeof(sem));
253 state.unique_keys = unique_keys;
275 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
276 errmsg(
"string too long to represent as jsonb string"),
277 errdetail(
"Due to an implementation restriction, jsonb strings cannot exceed %d bytes.",
325 v.
val.string.val = fname;
333 switch (scalarVal->
type)
347 if (scalarVal->
val.boolean)
353 elog(
ERROR,
"unknown jsonb scalar type");
374 v.
val.string.val = token;
392 v.
val.boolean =
true;
396 v.
val.boolean =
false;
413 va.
val.array.rawScalar =
true;
414 va.
val.array.nElems = 1;
433 elog(
ERROR,
"unexpected parent of nested structure");
475 bool redo_switch =
false;
478 int ispaces = indent ? 1 : 2;
484 bool use_indent =
false;
485 bool raw_scalar =
false;
486 bool last_was_key =
false;
495 while (redo_switch ||
505 if (!v.
val.array.rawScalar)
507 add_indent(out, use_indent && !last_was_key, level);
520 add_indent(out, use_indent && !last_was_key, level);
580 elog(
ERROR,
"unknown jsonb iterator token type");
583 last_was_key = redo_switch;
599 for (
i = 0;
i < level;
i++)
670 || typoid == ANYCOMPATIBLEARRAYOID || typoid == RECORDARRAYOID)
693 *outfuncoid = castfunc;
728 bool scalar_jsonb =
false;
738 else if (key_scalar &&
746 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
747 errmsg(
"key value must be scalar, not array, composite, or json")));
767 jb.
val.string.len = strlen(outputstr);
768 jb.
val.string.val = outputstr;
782 jb.
val.string.len = strlen(outputstr);
783 jb.
val.string.val = outputstr;
792 numeric_error = (strchr(outputstr,
'N') != NULL ||
793 strchr(outputstr,
'n') != NULL);
809 jb.
val.string.len = strlen(outputstr);
810 jb.
val.string.val = outputstr;
818 jb.
val.string.len = strlen(jb.
val.string.val);
824 jb.
val.string.len = strlen(jb.
val.string.val);
829 TIMESTAMPTZOID, NULL);
830 jb.
val.string.len = strlen(jb.
val.string.val);
842 memset(&sem, 0,
sizeof(sem));
892 jb.
val.string.val = outputstr;
898 if (!is_null && !scalar_jsonb &&
910 va.
val.array.rawScalar =
true;
911 va.
val.array.nElems = 1;
932 elog(
ERROR,
"unexpected parent of nested structure");
953 for (
i = 1;
i <= dims[dim];
i++)
955 if (dim + 1 == ndims)
957 datum_to_jsonb(vals[*valcount], nulls[*valcount], result, tcategory,
964 valcount, tcategory, outfuncoid);
1006 &tcategory, &outfuncoid);
1047 for (
i = 0;
i < tupdesc->
natts;
i++)
1057 if (att->attisdropped)
1096 Oid val_type,
bool key_scalar)
1103 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1104 errmsg(
"could not determine input data type")));
1113 &tcategory, &outfuncoid);
1176 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1177 errmsg(
"could not determine input data type")));
1180 &tcategory, &outfuncoid);
1187 bool absent_on_null,
bool unique_keys)
1194 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1195 errmsg(
"argument list must have even number of elements"),
1197 errhint(
"The arguments of %s must consist of alternating keys and values.",
1198 "jsonb_build_object()")));
1206 for (
i = 0;
i < nargs;
i += 2)
1213 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1214 errmsg(
"argument %d: key must not be null",
i + 1)));
1217 skip = absent_on_null && nulls[
i + 1];
1220 if (
skip && !unique_keys)
1272 bool absent_on_null)
1281 for (
i = 0;
i < nargs;
i++)
1283 if (absent_on_null && nulls[
i])
1364 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1365 errmsg(
"array must have even number of elements")));
1371 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1372 errmsg(
"array must have two columns")));
1377 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1378 errmsg(
"wrong number of array subscripts")));
1383 count = in_count / 2;
1385 for (
i = 0;
i < count; ++
i)
1391 if (in_nulls[
i * 2])
1393 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
1394 errmsg(
"null value not allowed for object key")));
1406 if (in_nulls[
i * 2 + 1])
1459 if (nkdims > 1 || nkdims != nvdims)
1461 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1462 errmsg(
"wrong number of array subscripts")));
1470 if (key_count != val_count)
1472 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1473 errmsg(
"mismatched array dimensions")));
1475 for (
i = 0;
i < key_count; ++
i)
1483 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
1484 errmsg(
"null value not allowed for object key")));
1550 icursor = icursor->
next;
1551 if (icursor == NULL)
1554 ocursor = ocursor->
next;
1556 ocursor->
next = NULL;
1570 bool single_scalar =
false;
1579 elog(
ERROR,
"jsonb_agg_transfn called in non-aggregate context");
1590 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1591 errmsg(
"could not determine input data type")));
1596 state->res = result;
1602 &
state->val_output_func);
1607 result =
state->res;
1620 state->val_output_func,
false);
1635 if (v.
val.array.rawScalar)
1636 single_scalar =
true;
1673 elog(
ERROR,
"unknown jsonb iterator token type");
1734 bool absent_on_null,
bool unique_keys)
1753 elog(
ERROR,
"jsonb_object_agg_transfn called in non-aggregate context");
1765 state->res = result;
1777 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1778 errmsg(
"could not determine input data type")));
1781 &
state->key_output_func);
1787 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1788 errmsg(
"could not determine input data type")));
1791 &
state->val_output_func);
1796 result =
state->res;
1803 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1804 errmsg(
"field name must not be null")));
1812 if (
skip && !unique_keys)
1820 state->key_output_func,
true);
1829 state->val_output_func,
false);
1850 if (!v.
val.array.rawScalar)
1851 elog(
ERROR,
"unexpected structure for key");
1865 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1866 errmsg(
"object keys must be strings")));
1884 elog(
ERROR,
"unexpected structure for key");
1891 single_scalar =
false;
1904 if (v.
val.array.rawScalar)
1905 single_scalar =
true;
1943 elog(
ERROR,
"unknown jsonb iterator token type");
2048 Assert(tmp.
val.array.nElems == 1 && tmp.
val.array.rawScalar);
2089 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2090 errmsg(messages[
i].msg, sqltype)));
2230 jbv.
val.array.elems = NULL;
2231 jbv.
val.array.nElems = 0;
2232 jbv.
val.array.rawScalar =
false;
2246 jbv.
val.object.pairs = NULL;
2247 jbv.
val.object.nPairs = 0;
2267 return pstrdup(v.
val.boolean ?
"true" :
"false");
#define PG_GETARG_ARRAYTYPE_P(n)
#define DatumGetArrayTypeP(X)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
int ArrayGetNItems(int ndim, const int *dims)
Datum numeric_int8(PG_FUNCTION_ARGS)
Datum numeric_uplus(PG_FUNCTION_ARGS)
Datum numeric_int4(PG_FUNCTION_ARGS)
Datum numeric_out(PG_FUNCTION_ARGS)
Datum numeric_int2(PG_FUNCTION_ARGS)
Datum numeric_float8(PG_FUNCTION_ARGS)
Datum numeric_in(PG_FUNCTION_ARGS)
Datum numeric_float4(PG_FUNCTION_ARGS)
#define TextDatumGetCString(d)
#define PG_USED_FOR_ASSERTS_ONLY
#define OidIsValid(objectId)
static void PGresult * res
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
char * OidOutputFunctionCall(Oid functionId, Datum val)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
#define OidFunctionCall1(functionId, arg1)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_RETURN_BYTEA_P(x)
#define DatumGetHeapTupleHeader(X)
#define DatumGetTextPP(X)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_DATUM(x)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
int extract_variadic_args(FunctionCallInfo fcinfo, int variadic_start, bool convert_unknown, Datum **args, Oid **types, bool **nulls)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
#define HeapTupleHeaderGetTypMod(tup)
#define HeapTupleHeaderGetTypeId(tup)
#define HeapTupleHeaderGetDatumLength(tup)
char * JsonEncodeDateTime(char *buf, Datum value, Oid typid, const int *tzp)
void escape_json(StringInfo buf, const char *str)
JsonLexContext * makeJsonLexContextCstringLen(char *json, int len, int encoding, bool need_escapes)
Datum jsonb_from_text(text *js, bool unique_keys)
Datum to_jsonb_worker(Datum val, JsonbTypeCategory tcategory, Oid outfuncoid)
static Datum jsonb_agg_transfn_worker(FunctionCallInfo fcinfo, bool absent_on_null)
Datum jsonb_int4(PG_FUNCTION_ARGS)
Datum jsonb_recv(PG_FUNCTION_ARGS)
Datum jsonb_object_agg_strict_transfn(PG_FUNCTION_ARGS)
Datum to_jsonb(PG_FUNCTION_ARGS)
Datum jsonb_build_array_noargs(PG_FUNCTION_ARGS)
Datum jsonb_object_agg_unique_strict_transfn(PG_FUNCTION_ARGS)
Datum jsonb_build_array_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null)
Datum jsonb_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types, bool absent_on_null, bool unique_keys)
Datum jsonb_in(PG_FUNCTION_ARGS)
Datum jsonb_build_object_noargs(PG_FUNCTION_ARGS)
Datum jsonb_agg_transfn(PG_FUNCTION_ARGS)
static Datum jsonb_from_cstring(char *json, int len, bool unique_keys)
Datum jsonb_object_two_arg(PG_FUNCTION_ARGS)
void jsonb_categorize_type(Oid typoid, JsonbTypeCategory *tcategory, Oid *outfuncoid)
Datum jsonb_object_agg_transfn(PG_FUNCTION_ARGS)
static char * JsonbToCStringWorker(StringInfo out, JsonbContainer *in, int estimated_len, bool indent)
Datum jsonb_build_array(PG_FUNCTION_ARGS)
Datum jsonb_int8(PG_FUNCTION_ARGS)
static void jsonb_put_escaped_value(StringInfo out, JsonbValue *scalarVal)
static void cannotCastJsonbValue(enum jbvType type, const char *sqltype)
static void jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype)
static void add_jsonb(Datum val, bool is_null, JsonbInState *result, Oid val_type, bool key_scalar)
static JsonbParseState * clone_parse_state(JsonbParseState *state)
char * JsonbToCStringIndent(StringInfo out, JsonbContainer *in, int estimated_len)
static const char * JsonbContainerTypeName(JsonbContainer *jbc)
Datum jsonb_object_agg_unique_transfn(PG_FUNCTION_ARGS)
static void datum_to_jsonb(Datum val, bool is_null, JsonbInState *result, JsonbTypeCategory tcategory, Oid outfuncoid, bool key_scalar)
Datum jsonb_out(PG_FUNCTION_ARGS)
static void array_dim_to_jsonb(JsonbInState *result, int dim, int ndims, int *dims, Datum *vals, bool *nulls, int *valcount, JsonbTypeCategory tcategory, Oid outfuncoid)
char * JsonbUnquote(Jsonb *jb)
Datum jsonb_numeric(PG_FUNCTION_ARGS)
static void jsonb_in_object_end(void *pstate)
static void array_to_jsonb_internal(Datum array, JsonbInState *result)
static void jsonb_in_array_start(void *pstate)
struct JsonbAggState JsonbAggState
Jsonb * JsonbMakeEmptyArray(void)
Datum jsonb_object(PG_FUNCTION_ARGS)
struct JsonbInState JsonbInState
Datum jsonb_int2(PG_FUNCTION_ARGS)
static void composite_to_jsonb(Datum composite, JsonbInState *result)
static void jsonb_in_object_start(void *pstate)
Datum jsonb_float4(PG_FUNCTION_ARGS)
Datum jsonb_agg_strict_transfn(PG_FUNCTION_ARGS)
static void add_indent(StringInfo out, bool indent, int level)
static size_t checkStringLen(size_t len)
Datum jsonb_object_agg_finalfn(PG_FUNCTION_ARGS)
bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)
Datum jsonb_build_object(PG_FUNCTION_ARGS)
static Datum jsonb_object_agg_transfn_worker(FunctionCallInfo fcinfo, bool absent_on_null, bool unique_keys)
Datum jsonb_typeof(PG_FUNCTION_ARGS)
Datum jsonb_bool(PG_FUNCTION_ARGS)
char * JsonbToCString(StringInfo out, JsonbContainer *in, int estimated_len)
Datum jsonb_agg_finalfn(PG_FUNCTION_ARGS)
Datum jsonb_float8(PG_FUNCTION_ARGS)
bool to_jsonb_is_immutable(Oid typoid)
static void jsonb_in_object_field_start(void *pstate, char *fname, bool isnull)
Jsonb * JsonbMakeEmptyObject(void)
const char * JsonbTypeName(JsonbValue *jbv)
Datum jsonb_send(PG_FUNCTION_ARGS)
static void jsonb_in_array_end(void *pstate)
#define JsonContainerIsScalar(jc)
#define JsonContainerIsArray(jc)
#define IsAJsonbScalar(jsonbval)
#define JENTRY_OFFLENMASK
#define JsonbPGetDatum(p)
#define PG_GETARG_JSONB_P(x)
#define JsonContainerIsObject(jc)
#define JB_ROOT_IS_SCALAR(jbp_)
#define DatumGetJsonbP(d)
JsonbIterator * JsonbIteratorInit(JsonbContainer *container)
Jsonb * JsonbValueToJsonb(JsonbValue *val)
JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val, bool skipNested)
JsonbValue * pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq, JsonbValue *jbval)
void pg_parse_json_or_ereport(JsonLexContext *lex, JsonSemAction *sem)
JsonLexContext * makeJsonLexContext(text *json, bool need_escapes)
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 get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
char func_volatile(Oid funcid)
Oid getBaseType(Oid typid)
int GetDatabaseEncoding(void)
char * pnstrdup(const char *in, Size len)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
#define DatumGetNumeric(X)
#define NumericGetDatum(X)
#define PG_RETURN_NUMERIC(x)
#define DatumGetNumericCopy(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 const struct exclude_list_item skip[]
void check_stack_depth(void)
#define CStringGetDatum(X)
#define ObjectIdGetDatum(X)
#define DatumGetCString(X)
#define PointerGetDatum(X)
#define VARSIZE_ANY_EXHDR(PTR)
StringInfo makeStringInfo(void)
void enlargeStringInfo(StringInfo str, int needed)
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
void appendStringInfoString(StringInfo str, const char *s)
StringInfoData * StringInfo
#define appendStringInfoCharMacro(str, ch)
json_struct_action array_end
json_struct_action object_start
json_ofield_action object_field_start
json_scalar_action scalar
json_struct_action array_start
json_struct_action object_end
JsonbTypeCategory key_category
JsonbTypeCategory val_category
JsonbParseState * parseState
struct JsonbParseState * next
#define FirstNormalObjectId
#define ReleaseTupleDesc(tupdesc)
#define TupleDescAttr(tupdesc, i)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
text * cstring_to_text(const char *s)