21#include "utils/fmgroids.h"
90 elog(
ERROR,
"unsupported jsonb version number %d", version);
191 switch (
val->val.datetime.typid)
196 return "time without time zone";
198 return "time with time zone";
200 return "timestamp without time zone";
202 return "timestamp with time zone";
204 elog(
ERROR,
"unrecognized jsonb value datetime type: %d",
205 val->val.datetime.typid);
209 elog(
ERROR,
"unrecognized jsonb value type: %d",
val->type);
250 state.unique_keys = unique_keys;
251 state.escontext = escontext;
274 errmsg(
"string too long to represent as jsonb string"),
275 errdetail(
"Due to an implementation restriction, jsonb strings cannot exceed %d bytes.",
333 v.
val.string.val = fname;
363 elog(
ERROR,
"unknown jsonb scalar type");
405 v.
val.boolean =
true;
409 v.
val.boolean =
false;
426 va.val.array.rawScalar =
true;
427 va.val.array.nElems = 1;
446 elog(
ERROR,
"unexpected parent of nested structure");
520 if (!v.
val.array.rawScalar)
595 elog(
ERROR,
"unknown jsonb iterator token type");
657 errmsg(
"key value must be scalar, not array, composite, or json")));
757 jb.val.string.len =
strlen(
jb.val.string.val);
763 jb.val.string.len =
strlen(
jb.val.string.val);
769 jb.val.string.len =
strlen(
jb.val.string.val);
865 va.val.array.rawScalar =
true;
866 va.val.array.nElems = 1;
887 elog(
ERROR,
"unexpected parent of nested structure");
908 for (
i = 1;
i <= dims[dim];
i++)
910 if (dim + 1 == ndims)
1002 for (
i = 0;
i < tupdesc->
natts;
i++)
1012 if (
att->attisdropped)
1061 errmsg(
"could not determine input data type")));
1103 errmsg(
"could not determine input data type")));
1131 bool absent_on_null,
bool unique_keys)
1139 errmsg(
"argument list must have even number of elements"),
1141 errhint(
"The arguments of %s must consist of alternating keys and values.",
1142 "jsonb_build_object()")));
1150 for (
i = 0;
i < nargs;
i += 2)
1158 errmsg(
"argument %d: key must not be null",
i + 1)));
1161 skip = absent_on_null && nulls[
i + 1];
1164 if (
skip && !unique_keys)
1190 &args, &
types, &nulls);
1216 bool absent_on_null)
1225 for (
i = 0;
i < nargs;
i++)
1227 if (absent_on_null && nulls[
i])
1250 &args, &
types, &nulls);
1309 errmsg(
"array must have even number of elements")));
1316 errmsg(
"array must have two columns")));
1322 errmsg(
"wrong number of array subscripts")));
1329 for (
i = 0;
i < count; ++
i)
1338 errmsg(
"null value not allowed for object key")));
1406 errmsg(
"wrong number of array subscripts")));
1417 errmsg(
"mismatched array dimensions")));
1428 errmsg(
"null value not allowed for object key")));
1485 elog(
ERROR,
"jsonb_agg_transfn called in non-aggregate context");
1497 errmsg(
"could not determine input data type")));
1500 result = &
state->pstate;
1505 &
state->val_output_func);
1510 result = &
state->pstate;
1525 state->val_output_func,
false);
1569 result =
arg->pstate;
1583 bool absent_on_null,
bool unique_keys)
1594 elog(
ERROR,
"jsonb_object_agg_transfn called in non-aggregate context");
1604 result = &
state->pstate;
1615 errmsg(
"could not determine input data type")));
1618 &
state->key_output_func);
1625 errmsg(
"could not determine input data type")));
1628 &
state->val_output_func);
1633 result = &
state->pstate;
1639 errmsg(
"field name must not be null")));
1647 if (
skip && !unique_keys)
1659 state->key_output_func,
true);
1664 state->val_output_func,
false);
1732 result =
arg->pstate;
1770 Assert(tmp.
val.array.nElems == 1 && tmp.
val.array.rawScalar);
1812 errmsg(messages[
i].msg, sqltype)));
2021 return pstrdup(v.
val.boolean ?
"true" :
"false");
#define PG_GETARG_ARRAYTYPE_P(n)
#define DatumGetArrayTypeP(X)
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
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)
Datum float8_numeric(PG_FUNCTION_ARGS)
Numeric int64_to_numeric(int64 val)
Datum float4_numeric(PG_FUNCTION_ARGS)
Datum numeric_int8(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)
bool numeric_is_nan(Numeric num)
Datum numeric_float4(PG_FUNCTION_ARGS)
bool numeric_is_inf(Numeric num)
#define TextDatumGetCString(d)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
int errcode(int sqlerrcode)
#define ereturn(context, dummy_value,...)
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
bool DirectInputFunctionCallSafe(PGFunction func, char *str, Oid typioparam, int32 typmod, Node *escontext, Datum *result)
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)
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
char * JsonEncodeDateTime(char *buf, Datum value, Oid typid, const int *tzp)
void escape_json_with_len(StringInfo buf, const char *str, int len)
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes)
void freeJsonLexContext(JsonLexContext *lex)
Datum jsonb_from_text(text *js, bool unique_keys)
static Datum jsonb_agg_transfn_worker(FunctionCallInfo fcinfo, bool absent_on_null)
static JsonParseErrorType jsonb_in_object_start(void *pstate)
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)
char * JsonbUnquote(Jsonb *jb)
Datum jsonb_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
static Datum jsonb_from_cstring(char *json, int len, bool unique_keys, Node *escontext)
static void datum_to_jsonb_internal(Datum val, bool is_null, JsonbInState *result, JsonTypeCategory tcategory, Oid outfuncoid, bool key_scalar)
Datum jsonb_build_array_noargs(PG_FUNCTION_ARGS)
Datum jsonb_object_agg_unique_strict_transfn(PG_FUNCTION_ARGS)
Datum jsonb_in(PG_FUNCTION_ARGS)
Datum jsonb_build_object_noargs(PG_FUNCTION_ARGS)
Datum jsonb_agg_transfn(PG_FUNCTION_ARGS)
Datum jsonb_object_two_arg(PG_FUNCTION_ARGS)
static const char * JsonbContainerTypeName(JsonbContainer *jbc)
Datum jsonb_object_agg_transfn(PG_FUNCTION_ARGS)
static JsonParseErrorType jsonb_in_array_end(void *pstate)
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 add_jsonb(Datum val, bool is_null, JsonbInState *result, Oid val_type, bool key_scalar)
static JsonParseErrorType jsonb_in_object_field_start(void *pstate, char *fname, bool isnull)
char * JsonbToCString(StringInfo out, JsonbContainer *in, int estimated_len)
Datum jsonb_object_agg_unique_transfn(PG_FUNCTION_ARGS)
Datum jsonb_out(PG_FUNCTION_ARGS)
Datum jsonb_numeric(PG_FUNCTION_ARGS)
static void array_to_jsonb_internal(Datum array, JsonbInState *result)
const char * JsonbTypeName(JsonbValue *val)
Datum jsonb_object(PG_FUNCTION_ARGS)
Datum jsonb_build_object_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null, bool unique_keys)
Datum jsonb_int2(PG_FUNCTION_ARGS)
static void composite_to_jsonb(Datum composite, JsonbInState *result)
Datum jsonb_float4(PG_FUNCTION_ARGS)
Datum jsonb_agg_strict_transfn(PG_FUNCTION_ARGS)
static void add_indent(StringInfo out, bool indent, int level)
Datum jsonb_object_agg_finalfn(PG_FUNCTION_ARGS)
static JsonParseErrorType jsonb_in_array_start(void *pstate)
bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)
Datum datum_to_jsonb(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
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 * JsonbToCStringIndent(StringInfo out, JsonbContainer *in, int estimated_len)
static JsonParseErrorType jsonb_in_object_end(void *pstate)
static JsonParseErrorType jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype)
Datum jsonb_agg_finalfn(PG_FUNCTION_ARGS)
Datum jsonb_float8(PG_FUNCTION_ARGS)
bool to_jsonb_is_immutable(Oid typoid)
static bool checkStringLen(size_t len, Node *escontext)
Datum jsonb_send(PG_FUNCTION_ARGS)
static void array_dim_to_jsonb(JsonbInState *result, int dim, int ndims, int *dims, const Datum *vals, const bool *nulls, int *valcount, JsonTypeCategory tcategory, Oid outfuncoid)
#define JsonContainerIsScalar(jc)
#define JsonContainerIsArray(jc)
static Datum JsonbPGetDatum(const Jsonb *p)
#define IsAJsonbScalar(jsonbval)
#define JENTRY_OFFLENMASK
#define PG_GETARG_JSONB_P(x)
#define JsonContainerIsObject(jc)
static Jsonb * DatumGetJsonbP(Datum d)
#define JB_ROOT_IS_SCALAR(jbp_)
void pushJsonbValue(JsonbInState *pstate, JsonbIteratorToken seq, JsonbValue *jbval)
JsonbIterator * JsonbIteratorInit(JsonbContainer *container)
JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val, bool skipNested)
Jsonb * JsonbValueToJsonb(JsonbValue *val)
JsonLexContext * makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes)
void json_check_mutability(Oid typoid, bool is_jsonb, bool *has_mutable)
void json_categorize_type(Oid typoid, bool is_jsonb, JsonTypeCategory *tcategory, Oid *outfuncoid)
bool pg_parse_json_or_errsave(JsonLexContext *lex, const JsonSemAction *sem, Node *escontext)
#define pg_parse_json_or_ereport(lex, sem)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
int GetDatabaseEncoding(void)
void * MemoryContextAllocZero(MemoryContext context, Size size)
char * pstrdup(const char *in)
void pfree(void *pointer)
char * pnstrdup(const char *in, Size len)
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
static Numeric DatumGetNumericCopy(Datum X)
static Numeric DatumGetNumeric(Datum X)
#define PG_RETURN_NUMERIC(x)
static Datum NumericGetDatum(Numeric X)
FormData_pg_attribute * Form_pg_attribute
static const struct exclude_list_item skip[]
static char buf[DEFAULT_XLOG_SEG_SIZE]
static bool DatumGetBool(Datum X)
static int64 DatumGetInt64(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static int16 DatumGetInt16(Datum X)
static int32 DatumGetInt32(Datum X)
void check_stack_depth(void)
struct StringInfoData * StringInfo
StringInfo makeStringInfo(void)
void enlargeStringInfo(StringInfo str, int needed)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoSpaces(StringInfo str, int count)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
#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
JsonTypeCategory val_category
JsonTypeCategory key_category
JsonbParseState * parseState
#define ReleaseTupleDesc(tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
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(const char *s)