PostgreSQL Source Code: src/backend/utils/adt/jsonb.c File Reference (original) (raw)

Go to the source code of this file.

Functions
static Datum jsonb_from_cstring (char *json, int len, bool unique_keys, Node *escontext)
static bool checkStringLen (size_t len, Node *escontext)
static JsonParseErrorType jsonb_in_object_start (void *pstate)
static JsonParseErrorType jsonb_in_object_end (void *pstate)
static JsonParseErrorType jsonb_in_array_start (void *pstate)
static JsonParseErrorType jsonb_in_array_end (void *pstate)
static JsonParseErrorType jsonb_in_object_field_start (void *pstate, char *fname, bool isnull)
static void jsonb_put_escaped_value (StringInfo out, JsonbValue *scalarVal)
static JsonParseErrorType jsonb_in_scalar (void *pstate, char *token, JsonTokenType tokentype)
static void composite_to_jsonb (Datum composite, JsonbInState *result)
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)
static void array_to_jsonb_internal (Datum array, JsonbInState *result)
static void datum_to_jsonb_internal (Datum val, bool is_null, JsonbInState *result, JsonTypeCategory tcategory, Oid outfuncoid, bool key_scalar)
static void add_jsonb (Datum val, bool is_null, JsonbInState *result, Oid val_type, bool key_scalar)
static JsonbParseState * clone_parse_state (JsonbParseState *state)
static char * JsonbToCStringWorker (StringInfo out, JsonbContainer *in, int estimated_len, bool indent)
static void add_indent (StringInfo out, bool indent, int level)
Datum jsonb_in (PG_FUNCTION_ARGS)
Datum jsonb_recv (PG_FUNCTION_ARGS)
Datum jsonb_out (PG_FUNCTION_ARGS)
Datum jsonb_send (PG_FUNCTION_ARGS)
Datum jsonb_from_text (text *js, bool unique_keys)
static const char * JsonbContainerTypeName (JsonbContainer *jbc)
const char * JsonbTypeName (JsonbValue *val)
Datum jsonb_typeof (PG_FUNCTION_ARGS)
char * JsonbToCString (StringInfo out, JsonbContainer *in, int estimated_len)
char * JsonbToCStringIndent (StringInfo out, JsonbContainer *in, int estimated_len)
bool to_jsonb_is_immutable (Oid typoid)
Datum to_jsonb (PG_FUNCTION_ARGS)
Datum datum_to_jsonb (Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
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_build_object (PG_FUNCTION_ARGS)
Datum jsonb_build_object_noargs (PG_FUNCTION_ARGS)
Datum jsonb_build_array_worker (int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
Datum jsonb_build_array (PG_FUNCTION_ARGS)
Datum jsonb_build_array_noargs (PG_FUNCTION_ARGS)
Datum jsonb_object (PG_FUNCTION_ARGS)
Datum jsonb_object_two_arg (PG_FUNCTION_ARGS)
static Datum jsonb_agg_transfn_worker (FunctionCallInfo fcinfo, bool absent_on_null)
Datum jsonb_agg_transfn (PG_FUNCTION_ARGS)
Datum jsonb_agg_strict_transfn (PG_FUNCTION_ARGS)
Datum jsonb_agg_finalfn (PG_FUNCTION_ARGS)
static Datum jsonb_object_agg_transfn_worker (FunctionCallInfo fcinfo, bool absent_on_null, bool unique_keys)
Datum jsonb_object_agg_transfn (PG_FUNCTION_ARGS)
Datum jsonb_object_agg_strict_transfn (PG_FUNCTION_ARGS)
Datum jsonb_object_agg_unique_transfn (PG_FUNCTION_ARGS)
Datum jsonb_object_agg_unique_strict_transfn (PG_FUNCTION_ARGS)
Datum jsonb_object_agg_finalfn (PG_FUNCTION_ARGS)
bool JsonbExtractScalar (JsonbContainer *jbc, JsonbValue *res)
static void cannotCastJsonbValue (enum jbvType type, const char *sqltype)
Datum jsonb_bool (PG_FUNCTION_ARGS)
Datum jsonb_numeric (PG_FUNCTION_ARGS)
Datum jsonb_int2 (PG_FUNCTION_ARGS)
Datum jsonb_int4 (PG_FUNCTION_ARGS)
Datum jsonb_int8 (PG_FUNCTION_ARGS)
Datum jsonb_float4 (PG_FUNCTION_ARGS)
Datum jsonb_float8 (PG_FUNCTION_ARGS)
char * JsonbUnquote (Jsonb *jb)

JsonbAggState

JsonbInState

add_indent()

static void add_indent ( StringInfo out, bool indent, int level ) static

add_jsonb()

static void add_jsonb ( Datum val, bool is_null, JsonbInState * result, Oid val_type, bool key_scalar ) static

Definition at line 1016 of file jsonb.c.

1018{

1020 Oid outfuncoid;

1021

1024 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1025 errmsg("could not determine input data type")));

1026

1027 if (is_null)

1028 {

1031 }

1032 else

1034 &tcategory, &outfuncoid);

1035

1037 key_scalar);

1038}

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

static void datum_to_jsonb_internal(Datum val, bool is_null, JsonbInState *result, JsonTypeCategory tcategory, Oid outfuncoid, bool key_scalar)

void json_categorize_type(Oid typoid, bool is_jsonb, JsonTypeCategory *tcategory, Oid *outfuncoid)

References datum_to_jsonb_internal(), ereport, errcode(), errmsg(), ERROR, InvalidOid, json_categorize_type(), JSONTYPE_NULL, and val.

Referenced by jsonb_build_array_worker(), and jsonb_build_object_worker().

array_dim_to_jsonb()

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 ) static

Definition at line 862 of file jsonb.c.

865{

866 int i;

867

869

871

872 for (i = 1; i <= dims[dim]; i++)

873 {

874 if (dim + 1 == ndims)

875 {

877 outfuncoid, false);

878 (*valcount)++;

879 }

880 else

881 {

883 valcount, tcategory, outfuncoid);

884 }

885 }

886

888}

Assert(PointerIsAligned(start, uint64))

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)

JsonbValue * pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq, JsonbValue *jbval)

JsonbParseState * parseState

References array_dim_to_jsonb(), Assert(), datum_to_jsonb_internal(), i, JsonbInState::parseState, pushJsonbValue(), JsonbInState::res, WJB_BEGIN_ARRAY, and WJB_END_ARRAY.

Referenced by array_dim_to_jsonb(), and array_to_jsonb_internal().

array_to_jsonb_internal()

Definition at line 894 of file jsonb.c.

895{

898 int *dim;

899 int ndim;

901 int count = 0;

903 bool *nulls;

905 bool typbyval;

908 Oid outfuncoid;

909

913

915 {

918 return;

919 }

920

922 &typlen, &typbyval, &typalign);

923

925 &tcategory, &outfuncoid);

926

930

931 array_dim_to_jsonb(result, 0, ndim, dim, elements, nulls, &count, tcategory,

932 outfuncoid);

933

936}

#define DatumGetArrayTypeP(X)

void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)

int ArrayGetNItems(int ndim, const int *dims)

void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)

void pfree(void *pointer)

References ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, array_dim_to_jsonb(), ArrayGetNItems(), DatumGetArrayTypeP, deconstruct_array(), get_typlenbyvalalign(), json_categorize_type(), nitems, JsonbInState::parseState, pfree(), pushJsonbValue(), JsonbInState::res, typalign, WJB_BEGIN_ARRAY, and WJB_END_ARRAY.

Referenced by datum_to_jsonb_internal().

cannotCastJsonbValue()

static void cannotCastJsonbValue ( enum jbvType type, const char * sqltype ) static

Definition at line 2008 of file jsonb.c.

2009{

2010 static const struct

2011 {

2013 const char *msg;

2014 }

2015 messages[] =

2016 {

2024 };

2025 int i;

2026

2027 for (i = 0; i < lengthof(messages); i++)

2030 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

2031 errmsg(messages[i].msg, sqltype)));

2032

2033

2034 elog(ERROR, "unknown jsonb type: %d", (int) type);

2035}

References elog, ereport, errcode(), errmsg(), ERROR, gettext_noop, i, jbvArray, jbvBinary, jbvBool, jbvNull, jbvNumeric, jbvObject, jbvString, lengthof, and type.

Referenced by jsonb_bool(), jsonb_float4(), jsonb_float8(), jsonb_int2(), jsonb_int4(), jsonb_int8(), and jsonb_numeric().

checkStringLen()

static bool checkStringLen ( size_t len, Node * escontext ) static

Definition at line 277 of file jsonb.c.

278{

280 ereturn(escontext, false,

281 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

282 errmsg("string too long to represent as jsonb string"),

283 errdetail("Due to an implementation restriction, jsonb strings cannot exceed %d bytes.",

285

286 return true;

287}

int errdetail(const char *fmt,...)

#define ereturn(context, dummy_value,...)

#define JENTRY_OFFLENMASK

References ereturn, errcode(), errdetail(), errmsg(), JENTRY_OFFLENMASK, and len.

Referenced by datum_to_jsonb_internal(), jsonb_in_object_field_start(), and jsonb_in_scalar().

clone_parse_state()

composite_to_jsonb()

Definition at line 942 of file jsonb.c.

943{

945 Oid tupType;

949 *tuple;

950 int i;

951

953

954

958

959

962 tuple = &tmptup;

963

965

966 for (i = 0; i < tupdesc->natts; i++)

967 {

969 bool isnull;

972 Oid outfuncoid;

975

976 if (att->attisdropped)

977 continue;

978

980

982

985

987

989

990 if (isnull)

991 {

994 }

995 else

997 &outfuncoid);

998

1000 false);

1001 }

1002

1005}

#define DatumGetHeapTupleHeader(X)

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)

FormData_pg_attribute * Form_pg_attribute

#define ReleaseTupleDesc(tupdesc)

static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)

TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)

References attname, datum_to_jsonb_internal(), DatumGetHeapTupleHeader, heap_getattr(), HeapTupleHeaderGetDatumLength(), HeapTupleHeaderGetTypeId(), HeapTupleHeaderGetTypMod(), i, InvalidOid, jbvString, json_categorize_type(), JSONTYPE_NULL, lookup_rowtype_tupdesc(), NameStr, TupleDescData::natts, JsonbInState::parseState, pushJsonbValue(), ReleaseTupleDesc, JsonbInState::res, HeapTupleData::t_data, HeapTupleData::t_len, TupleDescAttr(), JsonbValue::type, JsonbValue::val, val, WJB_BEGIN_OBJECT, WJB_END_OBJECT, and WJB_KEY.

Referenced by datum_to_jsonb_internal().

datum_to_jsonb()

datum_to_jsonb_internal()

Definition at line 638 of file jsonb.c.

641{

642 char *outputstr;

643 bool numeric_error;

645 bool scalar_jsonb = false;

646

648

649

650 if (is_null)

651 {

654 }

655 else if (key_scalar &&

661 {

663 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

664 errmsg("key value must be scalar, not array, composite, or json")));

665 }

666 else

667 {

670

671 switch (tcategory)

672 {

675 break;

678 break;

680 if (key_scalar)

681 {

684 jb.val.string.len = strlen(outputstr);

685 jb.val.string.val = outputstr;

686 }

687 else

688 {

691 }

692 break;

695 if (key_scalar)

696 {

697

699 jb.val.string.len = strlen(outputstr);

700 jb.val.string.val = outputstr;

701 }

702 else

703 {

704

705

706

707

708

709 numeric_error = (strchr(outputstr, 'N') != NULL ||

710 strchr(outputstr, 'n') != NULL);

711 if (!numeric_error)

712 {

714

721 pfree(outputstr);

722 }

723 else

724 {

726 jb.val.string.len = strlen(outputstr);

727 jb.val.string.val = outputstr;

728 }

729 }

730 break;

734 DATEOID, NULL);

735 jb.val.string.len = strlen(jb.val.string.val);

736 break;

740 TIMESTAMPOID, NULL);

741 jb.val.string.len = strlen(jb.val.string.val);

742 break;

746 TIMESTAMPTZOID, NULL);

747 jb.val.string.len = strlen(jb.val.string.val);

748 break;

751 {

752

756

758

759 memset(&sem, 0, sizeof(sem));

760

762

769

772 }

773 break;

775 {

778

780

782 {

786 scalar_jsonb = true;

787 }

788 else

789 {

791

794 {

799 else

802 }

803 }

804 }

805 break;

806 default:

809 jb.val.string.len = strlen(outputstr);

811 jb.val.string.val = outputstr;

812 break;

813 }

814 }

815

816

817 if (!is_null && !scalar_jsonb &&

819 {

820

821 return;

822 }

824 {

825

827

829 va.val.array.rawScalar = true;

830 va.val.array.nElems = 1;

831

835 }

836 else

837 {

839

840 switch (o->type)

841 {

844 break;

848 &jb);

849 break;

850 default:

851 elog(ERROR, "unexpected parent of nested structure");

852 }

853 }

854}

Datum numeric_in(PG_FUNCTION_ARGS)

char * OidOutputFunctionCall(Oid functionId, Datum val)

#define OidFunctionCall1(functionId, arg1)

#define DatumGetTextPP(X)

#define DirectFunctionCall3(func, arg1, arg2, arg3)

char * JsonEncodeDateTime(char *buf, Datum value, Oid typid, const int *tzp)

void freeJsonLexContext(JsonLexContext *lex)

static JsonParseErrorType jsonb_in_object_start(void *pstate)

static JsonParseErrorType jsonb_in_array_end(void *pstate)

static JsonParseErrorType jsonb_in_object_field_start(void *pstate, char *fname, bool isnull)

static void array_to_jsonb_internal(Datum array, JsonbInState *result)

static void composite_to_jsonb(Datum composite, JsonbInState *result)

static JsonParseErrorType jsonb_in_array_start(void *pstate)

static JsonParseErrorType jsonb_in_object_end(void *pstate)

static JsonParseErrorType jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype)

static bool checkStringLen(size_t len, Node *escontext)

static Jsonb * DatumGetJsonbP(Datum d)

#define JB_ROOT_IS_SCALAR(jbp_)

JsonbIterator * JsonbIteratorInit(JsonbContainer *container)

JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val, bool skipNested)

JsonLexContext * makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes)

#define pg_parse_json_or_ereport(lex, sem)

static Numeric DatumGetNumeric(Datum X)

static bool DatumGetBool(Datum X)

static Datum ObjectIdGetDatum(Oid X)

static Datum CStringGetDatum(const char *X)

static Datum Int32GetDatum(int32 X)

void check_stack_depth(void)

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

References JsonSemAction::array_end, JsonSemAction::array_start, array_to_jsonb_internal(), Assert(), check_stack_depth(), checkStringLen(), composite_to_jsonb(), JsonbParseState::contVal, CStringGetDatum(), DatumGetBool(), DatumGetJsonbP(), DatumGetNumeric(), DatumGetTextPP, DirectFunctionCall3, elog, ereport, errcode(), errmsg(), ERROR, freeJsonLexContext(), Int32GetDatum(), InvalidOid, JB_ROOT_IS_SCALAR, jbvArray, jbvBool, jbvNull, jbvNumeric, jbvObject, jbvString, jsonb_in_array_end(), jsonb_in_array_start(), jsonb_in_object_end(), jsonb_in_object_field_start(), jsonb_in_object_start(), jsonb_in_scalar(), JsonbIteratorInit(), JsonbIteratorNext(), JsonEncodeDateTime(), JSONTYPE_ARRAY, JSONTYPE_BOOL, JSONTYPE_CAST, JSONTYPE_COMPOSITE, JSONTYPE_DATE, JSONTYPE_JSON, JSONTYPE_JSONB, JSONTYPE_NUMERIC, JSONTYPE_TIMESTAMP, JSONTYPE_TIMESTAMPTZ, makeJsonLexContext(), numeric_in(), JsonSemAction::object_end, JsonSemAction::object_field_start, JsonSemAction::object_start, ObjectIdGetDatum(), OidFunctionCall1, OidOutputFunctionCall(), JsonbInState::parseState, pfree(), pg_parse_json_or_ereport, pushJsonbValue(), JsonbInState::res, Jsonb::root, JsonSemAction::scalar, sem, JsonSemAction::semstate, type, JsonbValue::type, JsonbValue::val, val, WJB_BEGIN_ARRAY, WJB_BEGIN_OBJECT, WJB_DONE, WJB_ELEM, WJB_END_ARRAY, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.

Referenced by add_jsonb(), array_dim_to_jsonb(), composite_to_jsonb(), datum_to_jsonb(), jsonb_agg_transfn_worker(), and jsonb_object_agg_transfn_worker().

jsonb_agg_finalfn()

Definition at line 1640 of file jsonb.c.

1641{

1645

1646

1648

1650 PG_RETURN_NULL();

1651

1653

1654

1655

1656

1657

1658

1659

1661

1663

1666

1668

1670}

#define PG_GETARG_POINTER(n)

#define PG_RETURN_POINTER(x)

static JsonbParseState * clone_parse_state(JsonbParseState *state)

int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)

References AggCheckCallContext(), arg, Assert(), clone_parse_state(), JsonbValueToJsonb(), JsonbInState::parseState, PG_ARGISNULL, PG_GETARG_POINTER, PG_RETURN_NULL, PG_RETURN_POINTER, pushJsonbValue(), JsonbInState::res, and WJB_END_ARRAY.

jsonb_agg_strict_transfn()

jsonb_agg_transfn()

jsonb_agg_transfn_worker()

Definition at line 1501 of file jsonb.c.

1502{

1504 aggcontext;

1509 bool single_scalar = false;

1514

1516 {

1517

1518 elog(ERROR, "jsonb_agg_transfn called in non-aggregate context");

1519 }

1520

1521

1522

1524 {

1526

1529 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1530 errmsg("could not determine input data type")));

1531

1535 state->res = result;

1539

1541 &state->val_output_func);

1542 }

1543 else

1544 {

1546 result = state->res;

1547 }

1548

1551

1552

1553

1555

1557

1559 state->val_output_func, false);

1560

1562

1563

1564

1566

1568

1570 {

1571 switch (type)

1572 {

1574 if (v.val.array.rawScalar)

1575 single_scalar = true;

1576 else

1578 type, NULL);

1579 break;

1581 if (!single_scalar)

1583 type, NULL);

1584 break;

1588 type, NULL);

1589 break;

1594 {

1595

1597

1599 v.val.string.val = buf;

1600 }

1602 {

1603

1604 v.val.numeric =

1607 }

1610 break;

1611 default:

1612 elog(ERROR, "unknown jsonb iterator token type");

1613 }

1614 }

1615

1617

1619}

Datum numeric_uplus(PG_FUNCTION_ARGS)

Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)

#define DirectFunctionCall1(func, arg1)

#define PG_GETARG_DATUM(n)

void * palloc0(Size size)

static Datum NumericGetDatum(Numeric X)

static MemoryContext MemoryContextSwitchTo(MemoryContext context)

References AggCheckCallContext(), buf, datum_to_jsonb_internal(), DatumGetNumeric(), DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, FunctionCallInfoBaseData::flinfo, get_fn_expr_argtype(), InvalidOid, jbvNumeric, jbvString, json_categorize_type(), JsonbIteratorInit(), JsonbIteratorNext(), JsonbValueToJsonb(), MemoryContextSwitchTo(), numeric_uplus(), NumericGetDatum(), palloc(), palloc0(), JsonbInState::parseState, PG_ARGISNULL, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, pushJsonbValue(), JsonbInState::res, Jsonb::root, snprintf, type, JsonbValue::type, JsonbValue::val, val, WJB_BEGIN_ARRAY, WJB_BEGIN_OBJECT, WJB_DONE, WJB_ELEM, WJB_END_ARRAY, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.

Referenced by jsonb_agg_strict_transfn(), and jsonb_agg_transfn().

jsonb_bool()

Definition at line 2038 of file jsonb.c.

2039{

2042

2045

2047 {

2050 }

2051

2054

2056

2058}

#define PG_FREE_IF_COPY(ptr, n)

#define PG_RETURN_BOOL(x)

static void cannotCastJsonbValue(enum jbvType type, const char *sqltype)

bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)

#define PG_GETARG_JSONB_P(x)

References cannotCastJsonbValue(), jbvBool, jbvNull, JsonbExtractScalar(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_RETURN_BOOL, PG_RETURN_NULL, Jsonb::root, JsonbValue::type, and JsonbValue::val.

jsonb_build_array()

Definition at line 1237 of file jsonb.c.

1238{

1240 bool *nulls;

1242

1243

1246

1247 if (nargs < 0)

1249

1251}

#define PG_RETURN_DATUM(x)

int extract_variadic_args(FunctionCallInfo fcinfo, int variadic_start, bool convert_unknown, Datum **args, Oid **types, bool **nulls)

Datum jsonb_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)

References generate_unaccent_rules::args, extract_variadic_args(), jsonb_build_array_worker(), PG_RETURN_DATUM, PG_RETURN_NULL, and types.

jsonb_build_array_noargs()

jsonb_build_array_worker()

Datum jsonb_build_array_worker ( int nargs,
const Datum * args,
const bool * nulls,
const Oid * types,
bool absent_on_null
)

Definition at line 1210 of file jsonb.c.

1212{

1213 int i;

1215

1217

1219

1220 for (i = 0; i < nargs; i++)

1221 {

1222 if (absent_on_null && nulls[i])

1223 continue;

1224

1226 }

1227

1229

1231}

static void add_jsonb(Datum val, bool is_null, JsonbInState *result, Oid val_type, bool key_scalar)

References add_jsonb(), generate_unaccent_rules::args, i, JsonbPGetDatum(), JsonbValueToJsonb(), JsonbInState::parseState, pushJsonbValue(), JsonbInState::res, types, WJB_BEGIN_ARRAY, and WJB_END_ARRAY.

Referenced by ExecEvalJsonConstructor(), and jsonb_build_array().

jsonb_build_object()

Definition at line 1177 of file jsonb.c.

1178{

1180 bool *nulls;

1182

1183

1186

1187 if (nargs < 0)

1189

1191}

Datum jsonb_build_object_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null, bool unique_keys)

References generate_unaccent_rules::args, extract_variadic_args(), jsonb_build_object_worker(), PG_RETURN_DATUM, PG_RETURN_NULL, and types.

jsonb_build_object_noargs()

jsonb_build_object_worker()

Datum jsonb_build_object_worker ( int nargs,
const Datum * args,
const bool * nulls,
const Oid * types,
bool absent_on_null,
bool unique_keys
)

Definition at line 1125 of file jsonb.c.

1127{

1128 int i;

1130

1131 if (nargs % 2 != 0)

1133 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1134 errmsg("argument list must have even number of elements"),

1135

1136 errhint("The arguments of %s must consist of alternating keys and values.",

1137 "jsonb_build_object()")));

1138

1140

1144

1145 for (i = 0; i < nargs; i += 2)

1146 {

1147

1149

1150 if (nulls[i])

1152 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1153 errmsg("argument %d: key must not be null", i + 1)));

1154

1155

1156 skip = absent_on_null && nulls[i + 1];

1157

1158

1159 if (skip && !unique_keys)

1160 continue;

1161

1163

1164

1166 }

1167

1169

1171}

int errhint(const char *fmt,...)

static const struct exclude_list_item skip[]

References add_jsonb(), generate_unaccent_rules::args, ereport, errcode(), errhint(), errmsg(), ERROR, i, JsonbPGetDatum(), JsonbValueToJsonb(), JsonbInState::parseState, pushJsonbValue(), JsonbInState::res, skip, JsonbParseState::skip_nulls, types, JsonbParseState::unique_keys, WJB_BEGIN_OBJECT, and WJB_END_OBJECT.

Referenced by ExecEvalJsonConstructor(), and jsonb_build_object().

jsonb_float4()

Definition at line 2172 of file jsonb.c.

2173{

2177

2180

2182 {

2185 }

2186

2189

2192

2194

2196}

Datum numeric_float4(PG_FUNCTION_ARGS)

References cannotCastJsonbValue(), DirectFunctionCall1, jbvNull, jbvNumeric, JsonbExtractScalar(), numeric_float4(), NumericGetDatum(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_RETURN_DATUM, PG_RETURN_NULL, Jsonb::root, JsonbValue::type, and JsonbValue::val.

jsonb_float8()

Definition at line 2199 of file jsonb.c.

2200{

2204

2207

2209 {

2212 }

2213

2216

2219

2221

2223}

Datum numeric_float8(PG_FUNCTION_ARGS)

References cannotCastJsonbValue(), DirectFunctionCall1, jbvNull, jbvNumeric, JsonbExtractScalar(), numeric_float8(), NumericGetDatum(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_RETURN_DATUM, PG_RETURN_NULL, Jsonb::root, JsonbValue::type, and JsonbValue::val.

jsonb_from_cstring()

static Datum jsonb_from_cstring ( char * json, int len, bool unique_keys, Node * escontext ) inlinestatic

Definition at line 248 of file jsonb.c.

249{

253

255 memset(&sem, 0, sizeof(sem));

257

258 state.unique_keys = unique_keys;

259 state.escontext = escontext;

261

268

270 return (Datum) 0;

271

272

274}

JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes)

bool pg_parse_json_or_errsave(JsonLexContext *lex, const JsonSemAction *sem, Node *escontext)

int GetDatabaseEncoding(void)

References JsonSemAction::array_end, JsonSemAction::array_start, GetDatabaseEncoding(), jsonb_in_array_end(), jsonb_in_array_start(), jsonb_in_object_end(), jsonb_in_object_field_start(), jsonb_in_object_start(), jsonb_in_scalar(), JsonbValueToJsonb(), len, makeJsonLexContextCstringLen(), JsonSemAction::object_end, JsonSemAction::object_field_start, JsonSemAction::object_start, pg_parse_json_or_errsave(), PG_RETURN_POINTER, JsonSemAction::scalar, sem, and JsonSemAction::semstate.

Referenced by jsonb_from_text(), jsonb_in(), and jsonb_recv().

jsonb_from_text()

Datum jsonb_from_text ( text * js,
bool unique_keys
)

jsonb_in()

jsonb_in_array_end()

jsonb_in_array_start()

jsonb_in_object_end()

jsonb_in_object_field_start()

static JsonParseErrorType jsonb_in_object_field_start ( void * pstate, char * fname, bool isnull ) static

Definition at line 331 of file jsonb.c.

332{

335

336 Assert(fname != NULL);

338 v.val.string.len = strlen(fname);

341 v.val.string.val = fname;

342

344

346}

References Assert(), checkStringLen(), JsonbInState::escontext, jbvString, JSON_SEM_ACTION_FAILED, JSON_SUCCESS, JsonbInState::parseState, pushJsonbValue(), JsonbInState::res, JsonbValue::type, JsonbValue::val, and WJB_KEY.

Referenced by datum_to_jsonb_internal(), and jsonb_from_cstring().

jsonb_in_object_start()

jsonb_in_scalar()

Definition at line 379 of file jsonb.c.

380{

384

385 switch (tokentype)

386 {

387

391 v.val.string.len = strlen(token);

395 break;

397

398

399

400

401

407 &numd))

410 break;

413 v.val.boolean = true;

414 break;

417 v.val.boolean = false;

418 break;

421 break;

422 default:

423

424 elog(ERROR, "invalid json token type");

425 break;

426 }

427

429 {

430

432

434 va.val.array.rawScalar = true;

435 va.val.array.nElems = 1;

436

440 }

441 else

442 {

444

445 switch (o->type)

446 {

449 break;

452 break;

453 default:

454 elog(ERROR, "unexpected parent of nested structure");

455 }

456 }

457

459}

bool DirectInputFunctionCallSafe(PGFunction func, char *str, Oid typioparam, int32 typmod, fmNodePtr escontext, Datum *result)

References Assert(), checkStringLen(), JsonbParseState::contVal, DatumGetNumeric(), DirectInputFunctionCallSafe(), elog, ERROR, JsonbInState::escontext, InvalidOid, jbvArray, jbvBool, jbvNull, jbvNumeric, jbvObject, jbvString, JSON_SEM_ACTION_FAILED, JSON_SUCCESS, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, numeric_in(), JsonbInState::parseState, pushJsonbValue(), JsonbInState::res, token, JsonbValue::type, JsonbValue::val, WJB_BEGIN_ARRAY, WJB_ELEM, WJB_END_ARRAY, and WJB_VALUE.

Referenced by datum_to_jsonb_internal(), and jsonb_from_cstring().

jsonb_int2()

Definition at line 2091 of file jsonb.c.

2092{

2096

2099

2101 {

2104 }

2105

2108

2111

2113

2115}

Datum numeric_int2(PG_FUNCTION_ARGS)

References cannotCastJsonbValue(), DirectFunctionCall1, jbvNull, jbvNumeric, JsonbExtractScalar(), numeric_int2(), NumericGetDatum(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_RETURN_DATUM, PG_RETURN_NULL, Jsonb::root, JsonbValue::type, and JsonbValue::val.

jsonb_int4()

Definition at line 2118 of file jsonb.c.

2119{

2123

2126

2128 {

2131 }

2132

2135

2138

2140

2142}

Datum numeric_int4(PG_FUNCTION_ARGS)

References cannotCastJsonbValue(), DirectFunctionCall1, jbvNull, jbvNumeric, JsonbExtractScalar(), numeric_int4(), NumericGetDatum(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_RETURN_DATUM, PG_RETURN_NULL, Jsonb::root, JsonbValue::type, and JsonbValue::val.

jsonb_int8()

Definition at line 2145 of file jsonb.c.

2146{

2150

2153

2155 {

2158 }

2159

2162

2165

2167

2169}

Datum numeric_int8(PG_FUNCTION_ARGS)

References cannotCastJsonbValue(), DirectFunctionCall1, jbvNull, jbvNumeric, JsonbExtractScalar(), numeric_int8(), NumericGetDatum(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_RETURN_DATUM, PG_RETURN_NULL, Jsonb::root, JsonbValue::type, and JsonbValue::val.

jsonb_numeric()

Definition at line 2061 of file jsonb.c.

2062{

2066

2069

2071 {

2074 }

2075

2078

2079

2080

2081

2082

2084

2086

2088}

static Numeric DatumGetNumericCopy(Datum X)

#define PG_RETURN_NUMERIC(x)

References cannotCastJsonbValue(), DatumGetNumericCopy(), jbvNull, jbvNumeric, JsonbExtractScalar(), NumericGetDatum(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_RETURN_NULL, PG_RETURN_NUMERIC, Jsonb::root, JsonbValue::type, and JsonbValue::val.

jsonb_object()

Definition at line 1279 of file jsonb.c.

1280{

1282 int ndims = ARR_NDIM(in_array);

1283 Datum *in_datums;

1284 bool *in_nulls;

1285 int in_count,

1286 count,

1287 i;

1289

1291

1293

1294 switch (ndims)

1295 {

1296 case 0:

1297 goto close_object;

1298 break;

1299

1300 case 1:

1301 if ((ARR_DIMS(in_array)[0]) % 2)

1303 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

1304 errmsg("array must have even number of elements")));

1305 break;

1306

1307 case 2:

1308 if ((ARR_DIMS(in_array)[1]) != 2)

1310 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

1311 errmsg("array must have two columns")));

1312 break;

1313

1314 default:

1316 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

1317 errmsg("wrong number of array subscripts")));

1318 }

1319

1321

1322 count = in_count / 2;

1323

1324 for (i = 0; i < count; ++i)

1325 {

1327 char *str;

1328 int len;

1329

1330 if (in_nulls[i * 2])

1332 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),

1333 errmsg("null value not allowed for object key")));

1334

1337

1339

1340 v.val.string.len = len;

1341 v.val.string.val = str;

1342

1344

1345 if (in_nulls[i * 2 + 1])

1346 {

1348 }

1349 else

1350 {

1353

1355

1356 v.val.string.len = len;

1357 v.val.string.val = str;

1358 }

1359

1361 }

1362

1363 pfree(in_datums);

1364 pfree(in_nulls);

1365

1366close_object:

1368

1370}

#define PG_GETARG_ARRAYTYPE_P(n)

void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)

#define TextDatumGetCString(d)

References ARR_DIMS, ARR_NDIM, deconstruct_array_builtin(), ereport, errcode(), errmsg(), ERROR, i, jbvNull, jbvString, JsonbValueToJsonb(), len, JsonbInState::parseState, pfree(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_POINTER, pushJsonbValue(), JsonbInState::res, str, TextDatumGetCString, JsonbValue::type, JsonbValue::val, WJB_BEGIN_OBJECT, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.

jsonb_object_agg_finalfn()

Definition at line 1930 of file jsonb.c.

1931{

1935

1936

1938

1940 PG_RETURN_NULL();

1941

1943

1944

1945

1946

1947

1948

1949

1950

1952

1954

1957

1959

1961}

References AggCheckCallContext(), arg, Assert(), clone_parse_state(), JsonbValueToJsonb(), JsonbInState::parseState, PG_ARGISNULL, PG_GETARG_POINTER, PG_RETURN_NULL, PG_RETURN_POINTER, pushJsonbValue(), JsonbInState::res, and WJB_END_OBJECT.

jsonb_object_agg_strict_transfn()

jsonb_object_agg_transfn()

jsonb_object_agg_transfn_worker()

static Datum jsonb_object_agg_transfn_worker ( FunctionCallInfo fcinfo, bool absent_on_null, bool unique_keys ) static

Definition at line 1673 of file jsonb.c.

1675{

1677 aggcontext;

1682 bool single_scalar;

1685 *jbval;

1689

1691 {

1692

1693 elog(ERROR, "jsonb_object_agg_transfn called in non-aggregate context");

1694 }

1695

1696

1697

1699 {

1700 Oid arg_type;

1701

1705 state->res = result;

1710

1712

1714

1717 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1718 errmsg("could not determine input data type")));

1719

1721 &state->key_output_func);

1722

1724

1727 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1728 errmsg("could not determine input data type")));

1729

1731 &state->val_output_func);

1732 }

1733 else

1734 {

1736 result = state->res;

1737 }

1738

1739

1740

1743 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1744 errmsg("field name must not be null")));

1745

1746

1747

1748

1749

1751

1752 if (skip && !unique_keys)

1754

1756

1758

1760 state->key_output_func, true);

1761

1763

1765

1767

1769 state->val_output_func, false);

1770

1772

1774

1775

1776

1778

1779

1780

1781

1782

1783

1784

1786 {

1787 switch (type)

1788 {

1790 if (!v.val.array.rawScalar)

1791 elog(ERROR, "unexpected structure for key");

1792 break;

1795 {

1796

1798

1800 v.val.string.val = buf;

1801 }

1802 else

1803 {

1805 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1806 errmsg("object keys must be strings")));

1807 }

1810

1812 {

1818 }

1819

1820 break;

1822 break;

1823 default:

1824 elog(ERROR, "unexpected structure for key");

1825 break;

1826 }

1827 }

1828

1830

1831 single_scalar = false;

1832

1833

1834

1835

1836

1837

1838

1840 {

1841 switch (type)

1842 {

1844 if (v.val.array.rawScalar)

1845 single_scalar = true;

1846 else

1848 type, NULL);

1849 break;

1851 if (!single_scalar)

1853 type, NULL);

1854 break;

1858 type, NULL);

1859 break;

1864 {

1865

1867

1869 v.val.string.val = buf;

1870 }

1872 {

1873

1874 v.val.numeric =

1877 }

1880 &v);

1881 break;

1882 default:

1883 elog(ERROR, "unknown jsonb iterator token type");

1884 }

1885 }

1886

1888

1890}

References AggCheckCallContext(), buf, datum_to_jsonb_internal(), DatumGetNumeric(), DirectFunctionCall1, elog, ereport, errcode(), errmsg(), ERROR, FunctionCallInfoBaseData::flinfo, get_fn_expr_argtype(), InvalidOid, jbvNull, jbvNumeric, jbvString, json_categorize_type(), JsonbIteratorInit(), JsonbIteratorNext(), JsonbValueToJsonb(), MemoryContextSwitchTo(), numeric_uplus(), NumericGetDatum(), palloc(), palloc0(), JsonbInState::parseState, PG_ARGISNULL, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, pushJsonbValue(), JsonbInState::res, Jsonb::root, skip, JsonbParseState::skip_nulls, snprintf, type, JsonbValue::type, JsonbParseState::unique_keys, JsonbValue::val, val, WJB_BEGIN_ARRAY, WJB_BEGIN_OBJECT, WJB_DONE, WJB_ELEM, WJB_END_ARRAY, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.

Referenced by jsonb_object_agg_strict_transfn(), jsonb_object_agg_transfn(), jsonb_object_agg_unique_strict_transfn(), and jsonb_object_agg_unique_transfn().

jsonb_object_agg_unique_strict_transfn()

jsonb_object_agg_unique_transfn()

jsonb_object_two_arg()

Definition at line 1379 of file jsonb.c.

1380{

1383 int nkdims = ARR_NDIM(key_array);

1384 int nvdims = ARR_NDIM(val_array);

1385 Datum *key_datums,

1386 *val_datums;

1387 bool *key_nulls,

1388 *val_nulls;

1389 int key_count,

1390 val_count,

1391 i;

1393

1395

1397

1398 if (nkdims > 1 || nkdims != nvdims)

1400 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

1401 errmsg("wrong number of array subscripts")));

1402

1403 if (nkdims == 0)

1404 goto close_object;

1405

1408

1409 if (key_count != val_count)

1411 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

1412 errmsg("mismatched array dimensions")));

1413

1414 for (i = 0; i < key_count; ++i)

1415 {

1417 char *str;

1418 int len;

1419

1420 if (key_nulls[i])

1422 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),

1423 errmsg("null value not allowed for object key")));

1424

1427

1429

1430 v.val.string.len = len;

1431 v.val.string.val = str;

1432

1434

1435 if (val_nulls[i])

1436 {

1438 }

1439 else

1440 {

1443

1445

1446 v.val.string.len = len;

1447 v.val.string.val = str;

1448 }

1449

1451 }

1452

1453 pfree(key_datums);

1454 pfree(key_nulls);

1455 pfree(val_datums);

1456 pfree(val_nulls);

1457

1458close_object:

1460

1462}

References ARR_NDIM, deconstruct_array_builtin(), ereport, errcode(), errmsg(), ERROR, i, jbvNull, jbvString, JsonbValueToJsonb(), len, JsonbInState::parseState, pfree(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_POINTER, pushJsonbValue(), JsonbInState::res, str, TextDatumGetCString, JsonbValue::type, JsonbValue::val, WJB_BEGIN_OBJECT, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.

jsonb_out()

jsonb_put_escaped_value()

Definition at line 349 of file jsonb.c.

350{

351 switch (scalarVal->type)

352 {

355 break;

358 break;

363 break;

365 if (scalarVal->val.boolean)

367 else

369 break;

370 default:

371 elog(ERROR, "unknown jsonb scalar type");

372 }

373}

Datum numeric_out(PG_FUNCTION_ARGS)

void escape_json_with_len(StringInfo buf, const char *str, int len)

static Datum PointerGetDatum(const void *X)

static char * DatumGetCString(Datum X)

void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)

void appendStringInfoString(StringInfo str, const char *s)

References appendBinaryStringInfo(), appendStringInfoString(), DatumGetCString(), DirectFunctionCall1, elog, ERROR, escape_json_with_len(), jbvBool, jbvNull, jbvNumeric, jbvString, numeric_out(), PointerGetDatum(), JsonbValue::type, and JsonbValue::val.

Referenced by JsonbToCStringWorker().

jsonb_recv()

Definition at line 89 of file jsonb.c.

90{

93 char *str;

94 int nbytes;

95

96 if (version == 1)

98 else

99 elog(ERROR, "unsupported jsonb version number %d", version);

100

102}

unsigned int pq_getmsgint(StringInfo msg, int b)

char * pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)

StringInfoData * StringInfo

References buf, elog, ERROR, jsonb_from_cstring(), PG_GETARG_POINTER, pq_getmsgint(), pq_getmsgtext(), and str.

jsonb_send()

Definition at line 124 of file jsonb.c.

125{

129 int version = 1;

130

132

137

139}

#define PG_RETURN_BYTEA_P(x)

void pq_sendtext(StringInfo buf, const char *str, int slen)

void pq_begintypsend(StringInfo buf)

bytea * pq_endtypsend(StringInfo buf)

static void pq_sendint8(StringInfo buf, uint8 i)

void destroyStringInfo(StringInfo str)

StringInfo makeStringInfo(void)

References buf, StringInfoData::data, destroyStringInfo(), JsonbToCString(), StringInfoData::len, makeStringInfo(), PG_GETARG_JSONB_P, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendint8(), pq_sendtext(), Jsonb::root, and VARSIZE.

jsonb_typeof()

JsonbContainerTypeName()

static const char * JsonbContainerTypeName ( JsonbContainer * jbc) static

JsonbExtractScalar()

Definition at line 1968 of file jsonb.c.

1969{

1973

1975 {

1976

1978 return false;

1979 }

1980

1981

1982

1983

1984

1986

1989 Assert(tmp.val.array.nElems == 1 && tmp.val.array.rawScalar);

1990

1994

1997

2000

2001 return true;

2002}

#define PG_USED_FOR_ASSERTS_ONLY

#define JsonContainerIsScalar(jc)

#define IsAJsonbScalar(jsonbval)

References Assert(), IsAJsonbScalar, jbvArray, jbvObject, JsonbIteratorInit(), JsonbIteratorNext(), JsonContainerIsArray, JsonContainerIsScalar, PG_USED_FOR_ASSERTS_ONLY, JsonbValue::type, JsonbValue::val, WJB_BEGIN_ARRAY, WJB_DONE, WJB_ELEM, and WJB_END_ARRAY.

Referenced by executeJsonPath(), jsonb_bool(), jsonb_float4(), jsonb_float8(), jsonb_int2(), jsonb_int4(), jsonb_int8(), jsonb_numeric(), JsonbContainerTypeName(), JsonbUnquote(), JsonItemFromDatum(), and JsonPathValue().

JsonbToCString()

JsonbToCStringIndent()

JsonbToCStringWorker()

Definition at line 491 of file jsonb.c.

492{

493 bool first = true;

497 int level = 0;

498 bool redo_switch = false;

499

500

501 int ispaces = indent ? 1 : 2;

502

503

504

505

506

507 bool use_indent = false;

508 bool raw_scalar = false;

509 bool last_was_key = false;

510

511 if (out == NULL)

513

514 enlargeStringInfo(out, (estimated_len >= 0) ? estimated_len : 64);

515

517

518 while (redo_switch ||

520 {

521 redo_switch = false;

522 switch (type)

523 {

525 if (!first)

527

528 if (!v.val.array.rawScalar)

529 {

530 add_indent(out, use_indent && !last_was_key, level);

532 }

533 else

534 raw_scalar = true;

535

536 first = true;

537 level++;

538 break;

540 if (!first)

542

543 add_indent(out, use_indent && !last_was_key, level);

545

546 first = true;

547 level++;

548 break;

550 if (!first)

552 first = true;

553

555

556

559

562 {

563 first = false;

565 }

566 else

567 {

569

570

571

572

573

574

575 redo_switch = true;

576 }

577 break;

579 if (!first)

581 first = false;

582

583 if (!raw_scalar)

586 break;

588 level--;

589 if (!raw_scalar)

590 {

593 }

594 first = false;

595 break;

597 level--;

600 first = false;

601 break;

602 default:

603 elog(ERROR, "unknown jsonb iterator token type");

604 }

605 use_indent = indent;

606 last_was_key = redo_switch;

607 }

608

610

611 return out->data;

612}

static void jsonb_put_escaped_value(StringInfo out, JsonbValue *scalarVal)

static void add_indent(StringInfo out, bool indent, int level)

void enlargeStringInfo(StringInfo str, int needed)

References add_indent(), appendBinaryStringInfo(), appendStringInfoCharMacro, Assert(), StringInfoData::data, elog, enlargeStringInfo(), ERROR, jsonb_put_escaped_value(), JsonbIteratorInit(), JsonbIteratorNext(), makeStringInfo(), type, JsonbValue::val, WJB_BEGIN_ARRAY, WJB_BEGIN_OBJECT, WJB_DONE, WJB_ELEM, WJB_END_ARRAY, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.

Referenced by JsonbToCString(), and JsonbToCStringIndent().

JsonbTypeName()

Definition at line 180 of file jsonb.c.

181{

182 switch (val->type)

183 {

187 return "object";

189 return "array";

191 return "number";

193 return "string";

195 return "boolean";

197 return "null";

199 switch (val->val.datetime.typid)

200 {

201 case DATEOID:

202 return "date";

203 case TIMEOID:

204 return "time without time zone";

205 case TIMETZOID:

206 return "time with time zone";

207 case TIMESTAMPOID:

208 return "timestamp without time zone";

209 case TIMESTAMPTZOID:

210 return "timestamp with time zone";

211 default:

212 elog(ERROR, "unrecognized jsonb value datetime type: %d",

213 val->val.datetime.typid);

214 }

215 return "unknown";

216 default:

217 elog(ERROR, "unrecognized jsonb value type: %d", val->type);

218 return "unknown";

219 }

220}

References elog, ERROR, jbvArray, jbvBinary, jbvBool, jbvDatetime, jbvNull, jbvNumeric, jbvObject, jbvString, JsonbContainerTypeName(), and val.

Referenced by executeItemOptUnwrapTarget(), and JsonbContainerTypeName().

JsonbUnquote()

char * JsonbUnquote ( Jsonb * jb )

Definition at line 2229 of file jsonb.c.

2230{

2232 {

2234

2236

2238 return pnstrdup(v.val.string.val, v.val.string.len);

2240 return pstrdup(v.val.boolean ? "true" : "false");

2246 else

2247 {

2248 elog(ERROR, "unrecognized jsonb value type %d", v.type);

2249 return NULL;

2250 }

2251 }

2252 else

2254}

char * pstrdup(const char *in)

char * pnstrdup(const char *in, Size len)

References DatumGetCString(), DirectFunctionCall1, elog, ERROR, JB_ROOT_IS_SCALAR, jbvBool, jbvNull, jbvNumeric, jbvString, JsonbExtractScalar(), JsonbToCString(), numeric_out(), pnstrdup(), PointerGetDatum(), pstrdup(), Jsonb::root, JsonbValue::type, JsonbValue::val, and VARSIZE.

Referenced by json_populate_type().

to_jsonb()

Definition at line 1088 of file jsonb.c.

1089{

1093 Oid outfuncoid;

1094

1097 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

1098 errmsg("could not determine input data type")));

1099

1101 &tcategory, &outfuncoid);

1102

1104}

Datum datum_to_jsonb(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)

References datum_to_jsonb(), ereport, errcode(), errmsg(), ERROR, get_fn_expr_argtype(), InvalidOid, json_categorize_type(), PG_GETARG_DATUM, PG_RETURN_DATUM, and val.

to_jsonb_is_immutable()

bool to_jsonb_is_immutable ( Oid typoid )

Definition at line 1049 of file jsonb.c.

1050{

1052 Oid outfuncoid;

1053

1055

1056 switch (tcategory)

1057 {

1062 return true;

1063

1067 return false;

1068

1070 return false;

1071

1073 return false;

1074

1078 return func_volatile(outfuncoid) == PROVOLATILE_IMMUTABLE;

1079 }

1080

1081 return false;

1082}

char func_volatile(Oid funcid)

References func_volatile(), json_categorize_type(), JSONTYPE_ARRAY, JSONTYPE_BOOL, JSONTYPE_CAST, JSONTYPE_COMPOSITE, JSONTYPE_DATE, JSONTYPE_JSON, JSONTYPE_JSONB, JSONTYPE_NULL, JSONTYPE_NUMERIC, JSONTYPE_OTHER, JSONTYPE_TIMESTAMP, and JSONTYPE_TIMESTAMPTZ.

Referenced by contain_mutable_functions_walker().