PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "common/hashfn.h"
#include "funcapi.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "port/simd.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datetime.h"
#include "utils/fmgroids.h"
#include "utils/json.h"
#include "utils/jsonfuncs.h"
#include "utils/lsyscache.h"
#include "utils/typcache.h"
Go to the source code of this file.
Data Structures | |
struct | JsonUniqueHashEntry |
struct | JsonUniqueStackEntry |
struct | JsonUniqueParsingState |
struct | JsonUniqueBuilderState |
struct | JsonAggState |
Macros | |
#define | ESCAPE_JSON_FLUSH_AFTER 512 |
Typedefs | |
typedef struct HTAB * | JsonUniqueCheckState |
typedef struct JsonUniqueHashEntry | JsonUniqueHashEntry |
typedef struct JsonUniqueStackEntry | JsonUniqueStackEntry |
typedef struct JsonUniqueParsingState | JsonUniqueParsingState |
typedef struct JsonUniqueBuilderState | JsonUniqueBuilderState |
typedef struct JsonAggState | JsonAggState |
typedef struct JsonAggState JsonAggState |
typedef struct JsonUniqueBuilderState JsonUniqueBuilderState |
typedef struct HTAB* JsonUniqueCheckState |
typedef struct JsonUniqueHashEntry JsonUniqueHashEntry |
typedef struct JsonUniqueParsingState JsonUniqueParsingState |
typedef struct JsonUniqueStackEntry JsonUniqueStackEntry |
|
static |
Definition at line 602 of file json.c.
References datum_to_json_internal(), ereport, errcode(), errmsg(), ERROR, InvalidOid, json_categorize_type(), JSONTYPE_NULL, and val.
Referenced by json_build_array_worker(), and json_build_object_worker().
|
static |
Definition at line 431 of file json.c.
References appendStringInfoChar(), appendStringInfoString(), Assert, datum_to_json_internal(), and i.
Referenced by array_to_json_internal().
Datum array_to_json | ( | PG_FUNCTION_ARGS | ) |
Definition at line 630 of file json.c.
References array_to_json_internal(), cstring_to_text_with_len(), StringInfoData::data, StringInfoData::len, makeStringInfo(), PG_GETARG_DATUM, and PG_RETURN_TEXT_P.
|
static |
Definition at line 474 of file json.c.
References appendStringInfoString(), ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, array_dim_to_json(), ArrayGetNItems(), DatumGetArrayTypeP, deconstruct_array(), get_typlenbyvalalign(), json_categorize_type(), nitems, pfree(), and typalign.
Referenced by array_to_json(), array_to_json_pretty(), and datum_to_json_internal().
Datum array_to_json_pretty | ( | PG_FUNCTION_ARGS | ) |
Definition at line 646 of file json.c.
References array_to_json_internal(), cstring_to_text_with_len(), StringInfoData::data, StringInfoData::len, makeStringInfo(), PG_GETARG_BOOL, PG_GETARG_DATUM, and PG_RETURN_TEXT_P.
|
static |
Definition at line 1209 of file json.c.
References StringInfoData::data, StringInfoData::len, palloc(), SET_VARSIZE, VARDATA, and VARHDRSZ.
Referenced by json_agg_finalfn(), and json_object_agg_finalfn().
|
static |
Definition at line 521 of file json.c.
References appendBinaryStringInfo(), appendStringInfoChar(), attname, datum_to_json_internal(), DatumGetHeapTupleHeader, escape_json(), heap_getattr(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, i, InvalidOid, json_categorize_type(), JSONTYPE_NULL, lookup_rowtype_tupdesc(), NameStr, TupleDescData::natts, ReleaseTupleDesc, HeapTupleData::t_data, HeapTupleData::t_len, TupleDescAttr, and val.
Referenced by datum_to_json_internal(), row_to_json(), and row_to_json_pretty().
Datum datum_to_json | ( | Datum | val, |
JsonTypeCategory | tcategory, | ||
Oid | outfuncoid | ||
) |
Definition at line 763 of file json.c.
References cstring_to_text_with_len(), StringInfoData::data, datum_to_json_internal(), StringInfoData::len, makeStringInfo(), PointerGetDatum(), and val.
Referenced by ExecEvalJsonConstructor(), and to_json().
|
static |
Definition at line 179 of file json.c.
References appendBinaryStringInfo(), appendStringInfoChar(), appendStringInfoString(), array_to_json_internal(), Assert, buf, check_stack_depth(), composite_to_json(), DatumGetBool(), DatumGetPointer(), DatumGetTextPP, ereport, errcode(), errmsg(), ERROR, escape_json(), escape_json_text(), JsonEncodeDateTime(), JSONTYPE_ARRAY, JSONTYPE_BOOL, JSONTYPE_CAST, JSONTYPE_COMPOSITE, JSONTYPE_DATE, JSONTYPE_JSON, JSONTYPE_NUMERIC, JSONTYPE_TIMESTAMP, JSONTYPE_TIMESTAMPTZ, MAXDATELEN, OidFunctionCall1, OidOutputFunctionCall(), pfree(), val, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Referenced by add_json(), array_dim_to_json(), composite_to_json(), datum_to_json(), json_agg_transfn_worker(), and json_object_agg_transfn_worker().
static void escape_json | ( | StringInfo | buf, |
const char * | str | ||
) |
Definition at line 1602 of file json.c.
References appendStringInfoCharMacro, buf, escape_json_char(), and str.
Referenced by appendJSONKeyValue(), composite_to_json(), datum_to_json_internal(), escape_yaml(), ExplainDummyGroup(), ExplainOpenGroup(), ExplainProperty(), ExplainPropertyList(), ExplainPropertyListNested(), populate_scalar(), sn_object_field_start(), sn_scalar(), transform_string_values_object_field_start(), transformJsonTableColumn(), and write_jsonlog().
|
static |
Definition at line 1562 of file json.c.
References appendStringInfo(), appendStringInfoCharMacro, appendStringInfoString(), and buf.
Referenced by escape_json(), and escape_json_with_len().
void escape_json_text | ( | StringInfo | buf, |
const text * | txt | ||
) |
Definition at line 1736 of file json.c.
References buf, escape_json_with_len(), len, pfree(), pg_detoast_datum_packed(), str, unconstify, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Referenced by datum_to_json_internal(), json_object(), json_object_two_arg(), and transform_string_values_scalar().
void escape_json_with_len | ( | StringInfo | buf, |
const char * | str, | ||
int | len | ||
) |
Definition at line 1631 of file json.c.
References appendBinaryStringInfo(), appendStringInfoCharMacro, Assert, b, buf, chunk, enlargeStringInfo(), escape_json_char(), ESCAPE_JSON_FLUSH_AFTER, i, len, str, vector8_has(), vector8_has_le(), and vector8_load().
Referenced by AddFileToBackupManifest(), escape_json_text(), hstore_to_json(), hstore_to_json_loose(), jsonb_put_escaped_value(), populate_scalar(), and printJsonPathItem().
Datum json_agg_finalfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 879 of file json.c.
References AggCheckCallContext(), Assert, catenate_stringinfo_string(), PG_ARGISNULL, PG_GETARG_POINTER, PG_RETURN_NULL, and PG_RETURN_TEXT_P.
Datum json_agg_strict_transfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 870 of file json.c.
References json_agg_transfn_worker().
Datum json_agg_transfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 861 of file json.c.
References json_agg_transfn_worker().
|
static |
Definition at line 779 of file json.c.
References AggCheckCallContext(), appendStringInfoChar(), appendStringInfoString(), datum_to_json_internal(), elog, ereport, errcode(), errmsg(), ERROR, FunctionCallInfoBaseData::flinfo, get_fn_expr_argtype(), InvalidOid, json_categorize_type(), JSONTYPE_ARRAY, JSONTYPE_COMPOSITE, JSONTYPE_NULL, makeStringInfo(), MemoryContextSwitchTo(), palloc(), PG_ARGISNULL, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, and val.
Referenced by json_agg_strict_transfn(), and json_agg_transfn().
Datum json_build_array | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1374 of file json.c.
References generate_unaccent_rules::args, extract_variadic_args(), json_build_array_worker(), PG_RETURN_DATUM, PG_RETURN_NULL, and types.
Datum json_build_array_noargs | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1394 of file json.c.
References cstring_to_text_with_len(), and PG_RETURN_TEXT_P.
Datum json_build_array_worker | ( | int | nargs, |
const Datum * | args, | ||
const bool * | nulls, | ||
const Oid * | types, | ||
bool | absent_on_null | ||
) |
Definition at line 1344 of file json.c.
References add_json(), appendStringInfoChar(), appendStringInfoString(), generate_unaccent_rules::args, cstring_to_text_with_len(), StringInfoData::data, i, StringInfoData::len, makeStringInfo(), PointerGetDatum(), and types.
Referenced by ExecEvalJsonConstructor(), and json_build_array().
Datum json_build_object | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1318 of file json.c.
References generate_unaccent_rules::args, extract_variadic_args(), json_build_object_worker(), PG_RETURN_DATUM, PG_RETURN_NULL, and types.
Datum json_build_object_noargs | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1338 of file json.c.
References cstring_to_text_with_len(), and PG_RETURN_TEXT_P.
Datum json_build_object_worker | ( | int | nargs, |
const Datum * | args, | ||
const bool * | nulls, | ||
const Oid * | types, | ||
bool | absent_on_null, | ||
bool | unique_keys | ||
) |
Definition at line 1224 of file json.c.
References add_json(), appendStringInfoChar(), appendStringInfoString(), generate_unaccent_rules::args, JsonUniqueBuilderState::check, cstring_to_text_with_len(), StringInfoData::data, ereport, errcode(), errhint(), errmsg(), ERROR, i, json_unique_builder_get_throwawaybuf(), json_unique_builder_init(), json_unique_check_key(), sort-test::key, StringInfoData::len, makeStringInfo(), PointerGetDatum(), pstrdup(), skip, and types.
Referenced by ExecEvalJsonConstructor(), and json_build_object().
Datum json_in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 107 of file json.c.
References cstring_to_text(), makeJsonLexContext(), nullSemAction, PG_GETARG_CSTRING, pg_parse_json_or_errsave(), PG_RETURN_NULL, and PG_RETURN_TEXT_P.
Datum json_object | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1406 of file json.c.
References appendStringInfoChar(), appendStringInfoString(), ARR_DIMS, ARR_NDIM, cstring_to_text_with_len(), CStringGetTextDatum, StringInfoData::data, DatumGetPointer(), deconstruct_array_builtin(), ereport, errcode(), errmsg(), ERROR, escape_json_text(), i, initStringInfo(), StringInfoData::len, pfree(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_DATUM, and PG_RETURN_TEXT_P.
Datum json_object_agg_finalfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1186 of file json.c.
References AggCheckCallContext(), Assert, catenate_stringinfo_string(), PG_ARGISNULL, PG_GETARG_POINTER, PG_RETURN_NULL, and PG_RETURN_TEXT_P.
Datum json_object_agg_strict_transfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1159 of file json.c.
References json_object_agg_transfn_worker().
Datum json_object_agg_transfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1150 of file json.c.
References json_object_agg_transfn_worker().
|
static |
Definition at line 1002 of file json.c.
References AggCheckCallContext(), appendStringInfoString(), arg, StringInfoData::data, datum_to_json_internal(), elog, ereport, errcode(), errmsg(), ERROR, FunctionCallInfoBaseData::flinfo, get_fn_expr_argtype(), InvalidOid, json_categorize_type(), json_unique_builder_get_throwawaybuf(), json_unique_builder_init(), json_unique_check_key(), sort-test::key, StringInfoData::len, makeStringInfo(), MemoryContextStrdup(), MemoryContextSwitchTo(), palloc(), PG_ARGISNULL, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, and skip.
Referenced by json_object_agg_strict_transfn(), json_object_agg_transfn(), json_object_agg_unique_strict_transfn(), and json_object_agg_unique_transfn().
Datum json_object_agg_unique_strict_transfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1177 of file json.c.
References json_object_agg_transfn_worker().
Datum json_object_agg_unique_transfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1168 of file json.c.
References json_object_agg_transfn_worker().
Datum json_object_two_arg | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1490 of file json.c.
References appendStringInfoChar(), appendStringInfoString(), ARR_NDIM, cstring_to_text_with_len(), CStringGetTextDatum, StringInfoData::data, DatumGetPointer(), deconstruct_array_builtin(), ereport, errcode(), errmsg(), ERROR, escape_json_text(), i, initStringInfo(), StringInfoData::len, pfree(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_DATUM, and PG_RETURN_TEXT_P.
Datum json_out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 126 of file json.c.
References PG_GETARG_DATUM, PG_RETURN_CSTRING, and TextDatumGetCString.
Datum json_recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 152 of file json.c.
References buf, cstring_to_text_with_len(), GetDatabaseEncoding(), makeJsonLexContextCstringLen(), nullSemAction, PG_GETARG_POINTER, pg_parse_json_or_ereport, PG_RETURN_TEXT_P, pq_getmsgtext(), and str.
Datum json_send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 138 of file json.c.
References buf, PG_GETARG_TEXT_PP, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendtext(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Datum json_typeof | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1874 of file json.c.
References cstring_to_text(), elog, ERROR, json_errsave_error(), json_lex(), JSON_SUCCESS, JSON_TOKEN_ARRAY_START, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, makeJsonLexContext(), PG_GETARG_TEXT_PP, PG_RETURN_TEXT_P, JsonLexContext::token_type, and type.
|
static |
Definition at line 978 of file json.c.
References StringInfoData::data, initStringInfo(), StringInfoData::len, JsonUniqueBuilderState::mcxt, MemoryContextSwitchTo(), and JsonUniqueBuilderState::skipped_keys.
Referenced by json_build_object_worker(), and json_object_agg_transfn_worker().
|
static |
Definition at line 950 of file json.c.
References JsonUniqueBuilderState::check, CurrentMemoryContext, StringInfoData::data, json_unique_check_init(), JsonUniqueBuilderState::mcxt, and JsonUniqueBuilderState::skipped_keys.
Referenced by json_build_object_worker(), and json_object_agg_transfn_worker().
|
static |
Definition at line 932 of file json.c.
References ctl, CurrentMemoryContext, HASH_COMPARE, HASH_CONTEXT, hash_create(), HASH_ELEM, HASH_FUNCTION, json_unique_hash(), and json_unique_hash_match().
Referenced by json_unique_builder_init(), and json_validate().
|
static |
Definition at line 958 of file json.c.
References HASH_ENTER, hash_search(), JsonUniqueHashEntry::key, sort-test::key, JsonUniqueHashEntry::key_len, and JsonUniqueHashEntry::object_id.
Referenced by json_build_object_worker(), json_object_agg_transfn_worker(), and json_unique_object_field_start().
Definition at line 900 of file json.c.
References DatumGetUInt32(), hash(), hash_bytes(), hash_bytes_uint32(), JsonUniqueHashEntry::key, sort-test::key, JsonUniqueHashEntry::key_len, and JsonUniqueHashEntry::object_id.
Referenced by json_unique_check_init().
|
static |
Definition at line 911 of file json.c.
References JsonUniqueHashEntry::key, JsonUniqueHashEntry::key_len, and JsonUniqueHashEntry::object_id.
Referenced by json_unique_check_init().
|
static |
Definition at line 1772 of file json.c.
References JSON_SUCCESS, JsonUniqueStackEntry::parent, and pfree().
Referenced by json_validate().
|
static |
Definition at line 1787 of file json.c.
References JSON_SUCCESS, json_unique_check_key(), JsonUniqueStackEntry::parent, and pfree().
Referenced by json_validate().
|
static |
Definition at line 1754 of file json.c.
References JSON_SUCCESS, JsonUniqueStackEntry::object_id, palloc(), and JsonUniqueStackEntry::parent.
Referenced by json_validate().
Definition at line 1812 of file json.c.
References ereport, errcode(), errmsg(), ERROR, freeJsonLexContext(), json_errsave_error(), JSON_SUCCESS, json_unique_check_init(), json_unique_object_end(), json_unique_object_field_start(), json_unique_object_start(), makeJsonLexContext(), nullSemAction, JsonSemAction::object_end, JsonSemAction::object_field_start, JsonSemAction::object_start, pg_parse_json(), and JsonSemAction::semstate.
Referenced by ExecEvalJsonConstructor(), and ExecEvalJsonIsPredicate().
Definition at line 310 of file json.c.
References buf, DATE_NOT_FINITE, DatumGetDateADT(), DatumGetTimeADT(), DatumGetTimestamp(), DatumGetTimestampTz(), DatumGetTimeTzADTP(), elog, EncodeDateOnly(), EncodeDateTime(), EncodeSpecialDate(), EncodeSpecialTimestamp(), EncodeTimeOnly(), ereport, errcode(), errmsg(), ERROR, j2date(), MAXDATELEN, palloc(), POSTGRES_EPOCH_JDATE, time2tm(), timestamp2tm(), TIMESTAMP_NOT_FINITE, timetz2tm(), tm, pg_tm::tm_isdst, pg_tm::tm_mday, pg_tm::tm_mon, pg_tm::tm_year, USE_XSD_DATES, USECS_PER_SEC, and value.
Referenced by convertJsonbScalar(), datum_to_json_internal(), datum_to_jsonb_internal(), and executeItemOptUnwrapTarget().
Datum row_to_json | ( | PG_FUNCTION_ARGS | ) |
Definition at line 663 of file json.c.
References composite_to_json(), cstring_to_text_with_len(), StringInfoData::data, StringInfoData::len, makeStringInfo(), PG_GETARG_DATUM, and PG_RETURN_TEXT_P.
Datum row_to_json_pretty | ( | PG_FUNCTION_ARGS | ) |
Definition at line 679 of file json.c.
References composite_to_json(), cstring_to_text_with_len(), StringInfoData::data, StringInfoData::len, makeStringInfo(), PG_GETARG_BOOL, PG_GETARG_DATUM, and PG_RETURN_TEXT_P.
Datum to_json | ( | PG_FUNCTION_ARGS | ) |
Definition at line 739 of file json.c.
References datum_to_json(), ereport, errcode(), errmsg(), ERROR, get_fn_expr_argtype(), InvalidOid, json_categorize_type(), PG_GETARG_DATUM, PG_RETURN_DATUM, and val.
Definition at line 700 of file json.c.
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().