PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/htup_details.h"
#include "access/transam.h"
#include "catalog/pg_type.h"
#include "executor/spi.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "parser/parse_coerce.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datetime.h"
#include "utils/json.h"
#include "utils/jsonapi.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/typcache.h"
Go to the source code of this file.
Data Structures | |
struct | JsonAggState |
Macros | |
#define | JSON_ALPHANUMERIC_CHAR(c) |
Typedefs | |
typedef struct JsonAggState | JsonAggState |
Variables | |
static JsonSemAction | nullSemAction |
#define JSON_ALPHANUMERIC_CHAR | ( | c | ) |
Definition at line 180 of file json.c.
Referenced by json_lex(), and json_lex_number().
typedef struct JsonAggState JsonAggState |
enum JsonParseContext |
Enumerator | |
---|---|
JSON_PARSE_VALUE | |
JSON_PARSE_STRING | |
JSON_PARSE_ARRAY_START | |
JSON_PARSE_ARRAY_NEXT | |
JSON_PARSE_OBJECT_START | |
JSON_PARSE_OBJECT_LABEL | |
JSON_PARSE_OBJECT_NEXT | |
JSON_PARSE_OBJECT_COMMA | |
JSON_PARSE_END |
enum JsonTypeCategory |
Enumerator | |
---|---|
JSONTYPE_NULL | |
JSONTYPE_BOOL | |
JSONTYPE_NUMERIC | |
JSONTYPE_DATE | |
JSONTYPE_TIMESTAMP | |
JSONTYPE_TIMESTAMPTZ | |
JSONTYPE_JSON | |
JSONTYPE_ARRAY | |
JSONTYPE_COMPOSITE | |
JSONTYPE_CAST | |
JSONTYPE_OTHER |
|
static |
Definition at line 1840 of file json.c.
References datum_to_json(), ereport, errcode(), errmsg(), ERROR, InvalidOid, json_categorize_type(), and JSONTYPE_NULL.
Referenced by json_build_array(), and json_build_object().
|
static |
Definition at line 1678 of file json.c.
References appendStringInfoChar(), appendStringInfoString(), Assert, datum_to_json(), and i.
Referenced by array_to_json_internal().
Datum array_to_json | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1867 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 1720 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(), pfree(), and typalign.
Referenced by array_to_json(), array_to_json_pretty(), and datum_to_json().
Datum array_to_json_pretty | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1883 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 2177 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 1767 of file json.c.
References appendStringInfoChar(), appendStringInfoString(), attname, datum_to_json(), 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(), row_to_json(), and row_to_json_pretty().
|
static |
Definition at line 1450 of file json.c.
References appendStringInfo(), appendStringInfoString(), array_to_json_internal(), Assert, buf, check_stack_depth(), composite_to_json(), DatumGetBool, DatumGetTextPP, ereport, errcode(), errmsg(), ERROR, escape_json(), IsValidJsonNumber(), JsonEncodeDateTime(), JSONTYPE_ARRAY, JSONTYPE_BOOL, JSONTYPE_CAST, JSONTYPE_COMPOSITE, JSONTYPE_DATE, JSONTYPE_JSON, JSONTYPE_NUMERIC, JSONTYPE_TIMESTAMP, JSONTYPE_TIMESTAMPTZ, MAXDATELEN, OidFunctionCall1, OidOutputFunctionCall(), pfree(), and text_to_cstring().
Referenced by add_json(), array_dim_to_json(), composite_to_json(), json_agg_transfn(), json_object_agg_transfn(), and to_json().
void escape_json | ( | StringInfo | buf, |
const char * | str | ||
) |
Definition at line 2483 of file json.c.
References appendStringInfo(), appendStringInfoCharMacro, and appendStringInfoString().
Referenced by composite_to_json(), datum_to_json(), escape_yaml(), ExplainDummyGroup(), ExplainOpenGroup(), ExplainProperty(), ExplainPropertyList(), ExplainPropertyListNested(), hstore_to_json(), hstore_to_json_loose(), json_object(), json_object_two_arg(), jsonb_put_escaped_value(), populate_scalar(), printJsonPathItem(), sn_object_field_start(), sn_scalar(), transform_string_values_object_field_start(), and transform_string_values_scalar().
|
static |
Definition at line 1327 of file json.c.
References palloc(), and pg_mblen().
Referenced by json_lex_string().
bool IsValidJsonNumber | ( | const char * | str, |
int | len | ||
) |
Definition at line 193 of file json.c.
References JsonLexContext::input, JsonLexContext::input_length, json_lex_number(), and unconstify.
Referenced by datum_to_json(), hstore_to_json_loose(), and hstore_to_jsonb_loose().
Datum json_agg_finalfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2038 of file json.c.
References AggCheckCallContext(), Assert, catenate_stringinfo_string(), PG_ARGISNULL, PG_GETARG_POINTER, PG_RETURN_NULL, PG_RETURN_TEXT_P, and JsonAggState::str.
Datum json_agg_transfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1962 of file json.c.
References AggCheckCallContext(), appendStringInfoChar(), appendStringInfoString(), datum_to_json(), elog, ereport, errcode(), errmsg(), ERROR, 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, JsonAggState::str, val, JsonAggState::val_category, and JsonAggState::val_output_func.
Datum json_build_array | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2261 of file json.c.
References add_json(), appendStringInfoChar(), appendStringInfoString(), generate_unaccent_rules::args, cstring_to_text_with_len(), StringInfoData::data, extract_variadic_args(), i, StringInfoData::len, makeStringInfo(), PG_RETURN_NULL, PG_RETURN_TEXT_P, and types.
Datum json_build_array_noargs | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2297 of file json.c.
References cstring_to_text_with_len(), and PG_RETURN_TEXT_P.
Datum json_build_object | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2195 of file json.c.
References add_json(), appendStringInfoChar(), appendStringInfoString(), generate_unaccent_rules::args, cstring_to_text_with_len(), StringInfoData::data, ereport, errcode(), errhint(), errmsg(), ERROR, extract_variadic_args(), i, StringInfoData::len, makeStringInfo(), PG_NARGS, PG_RETURN_NULL, PG_RETURN_TEXT_P, and types.
Datum json_build_object_noargs | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2252 of file json.c.
References cstring_to_text_with_len(), and PG_RETURN_TEXT_P.
|
static |
Definition at line 1348 of file json.c.
References COERCION_EXPLICIT, COERCION_PATH_FUNC, find_coercion_pathway(), FirstNormalObjectId, get_element_type(), getBaseType(), getTypeOutputInfo(), InvalidOid, JSONTYPE_ARRAY, JSONTYPE_BOOL, JSONTYPE_CAST, JSONTYPE_COMPOSITE, JSONTYPE_DATE, JSONTYPE_JSON, JSONTYPE_NUMERIC, JSONTYPE_OTHER, JSONTYPE_TIMESTAMP, JSONTYPE_TIMESTAMPTZ, OidIsValid, and type_is_rowtype().
Referenced by add_json(), array_to_json_internal(), composite_to_json(), json_agg_transfn(), json_object_agg_transfn(), and to_json().
int json_count_array_elements | ( | JsonLexContext * | lex | ) |
Definition at line 367 of file json.c.
References JSON_PARSE_ARRAY_NEXT, JSON_PARSE_ARRAY_START, JSON_TOKEN_ARRAY_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_COMMA, lex_accept(), lex_expect(), JsonLexContext::lex_level, lex_peek(), parse_array_element(), and JsonLexContext::strval.
Referenced by get_array_start().
Datum json_in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 228 of file json.c.
References cstring_to_text(), makeJsonLexContext(), PG_GETARG_CSTRING, pg_parse_json(), and PG_RETURN_TEXT_P.
|
inlinestatic |
Definition at line 614 of file json.c.
References JsonLexContext::input, JsonLexContext::input_length, JSON_ALPHANUMERIC_CHAR, json_lex_number(), json_lex_string(), JSON_TOKEN_ARRAY_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_COLON, JSON_TOKEN_COMMA, JSON_TOKEN_END, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_OBJECT_END, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, JsonLexContext::line_number, JsonLexContext::prev_token_terminator, report_invalid_token(), JsonLexContext::token_start, JsonLexContext::token_terminator, and JsonLexContext::token_type.
Referenced by json_typeof(), lex_accept(), and pg_parse_json().
|
inlinestatic |
Definition at line 1028 of file json.c.
References error(), JsonLexContext::input, JsonLexContext::input_length, JSON_ALPHANUMERIC_CHAR, JsonLexContext::prev_token_terminator, report_invalid_token(), and JsonLexContext::token_terminator.
Referenced by IsValidJsonNumber(), and json_lex().
|
inlinestatic |
Definition at line 755 of file json.c.
References appendBinaryStringInfo(), appendStringInfoChar(), Assert, ereport, errcode(), errdetail(), errmsg(), ERROR, extract_mb_char(), GetDatabaseEncoding(), i, JsonLexContext::input, JsonLexContext::input_length, pg_mblen(), PG_UTF8, pg_utf_mblen(), JsonLexContext::prev_token_terminator, report_invalid_token(), report_json_context(), resetStringInfo(), JsonLexContext::strval, JsonLexContext::token_start, JsonLexContext::token_terminator, and unicode_to_utf8().
Referenced by json_lex().
Datum json_object | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2309 of file json.c.
References appendStringInfoChar(), appendStringInfoString(), ARR_DIMS, ARR_NDIM, cstring_to_text_with_len(), CStringGetTextDatum, StringInfoData::data, deconstruct_array(), ereport, errcode(), errmsg(), ERROR, escape_json(), i, initStringInfo(), StringInfoData::len, pfree(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_DATUM, PG_RETURN_TEXT_P, and TextDatumGetCString.
Datum json_object_agg_finalfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2154 of file json.c.
References AggCheckCallContext(), Assert, catenate_stringinfo_string(), PG_ARGISNULL, PG_GETARG_POINTER, PG_RETURN_NULL, PG_RETURN_TEXT_P, and JsonAggState::str.
Datum json_object_agg_transfn | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2063 of file json.c.
References AggCheckCallContext(), appendStringInfoString(), arg, datum_to_json(), elog, ereport, errcode(), errmsg(), ERROR, get_fn_expr_argtype(), InvalidOid, json_categorize_type(), JsonAggState::key_category, JsonAggState::key_output_func, makeStringInfo(), MemoryContextSwitchTo(), palloc(), PG_ARGISNULL, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, JsonAggState::str, JsonAggState::val_category, and JsonAggState::val_output_func.
Datum json_object_two_arg | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2400 of file json.c.
References appendStringInfoChar(), appendStringInfoString(), ARR_NDIM, cstring_to_text_with_len(), CStringGetTextDatum, StringInfoData::data, deconstruct_array(), ereport, errcode(), errmsg(), ERROR, escape_json(), i, initStringInfo(), StringInfoData::len, pfree(), PG_GETARG_ARRAYTYPE_P, PG_RETURN_DATUM, PG_RETURN_TEXT_P, and TextDatumGetCString.
Datum json_out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 246 of file json.c.
References PG_GETARG_DATUM, PG_RETURN_CSTRING, and TextDatumGetCString.
Datum json_recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 272 of file json.c.
References buf, cstring_to_text_with_len(), StringInfoData::cursor, StringInfoData::len, makeJsonLexContextCstringLen(), PG_GETARG_POINTER, pg_parse_json(), PG_RETURN_TEXT_P, pq_getmsgtext(), and JsonAggState::str.
Datum json_send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 258 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 2537 of file json.c.
References cstring_to_text(), elog, ERROR, json_lex(), JSON_TOKEN_ARRAY_START, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, lex_peek(), makeJsonLexContext(), PG_GETARG_TEXT_PP, PG_RETURN_TEXT_P, and generate_unaccent_rules::type.
Definition at line 1557 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, and USECS_PER_SEC.
Referenced by convertJsonbScalar(), datum_to_json(), and datum_to_jsonb().
|
inlinestatic |
Definition at line 139 of file json.c.
References StringInfoData::data, json_lex(), JSON_TOKEN_STRING, palloc(), pstrdup(), JsonLexContext::strval, JsonLexContext::token_start, JsonLexContext::token_terminator, and JsonLexContext::token_type.
Referenced by json_count_array_elements(), lex_expect(), parse_array(), parse_object(), parse_object_field(), and parse_scalar().
|
inlinestatic |
Definition at line 173 of file json.c.
References lex_accept(), and report_parse_error().
Referenced by json_count_array_elements(), parse_array(), parse_object(), parse_object_field(), and pg_parse_json().
|
inlinestatic |
Definition at line 124 of file json.c.
References JsonLexContext::token_type.
Referenced by json_count_array_elements(), json_typeof(), parse_array(), parse_array_element(), parse_object(), parse_object_field(), parse_scalar(), and pg_parse_json().
JsonLexContext* makeJsonLexContext | ( | text * | json, |
bool | need_escapes | ||
) |
Definition at line 301 of file json.c.
References makeJsonLexContextCstringLen(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Referenced by datum_to_jsonb(), each_worker(), elements_worker(), get_worker(), iterate_json_values(), json_array_length(), json_in(), json_object_keys(), json_strip_nulls(), json_typeof(), populate_recordset_worker(), and transform_json_string_values().
JsonLexContext* makeJsonLexContextCstringLen | ( | char * | json, |
int | len, | ||
bool | need_escapes | ||
) |
Definition at line 309 of file json.c.
References JsonLexContext::input, JsonLexContext::input_length, JsonLexContext::line_number, JsonLexContext::line_start, makeStringInfo(), palloc0(), JsonLexContext::strval, and JsonLexContext::token_terminator.
Referenced by get_json_object_as_hash(), json_recv(), jsonb_from_cstring(), makeJsonLexContext(), and populate_array_json().
|
static |
Definition at line 570 of file json.c.
References JsonSemAction::array_end, JsonSemAction::array_start, check_stack_depth(), JSON_PARSE_ARRAY_NEXT, JSON_PARSE_ARRAY_START, JSON_TOKEN_ARRAY_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_COMMA, lex_accept(), lex_expect(), JsonLexContext::lex_level, lex_peek(), parse_array_element(), and JsonSemAction::semstate.
Referenced by parse_array_element(), parse_object_field(), and pg_parse_json().
|
static |
Definition at line 539 of file json.c.
References JsonSemAction::array_element_end, JsonSemAction::array_element_start, JSON_TOKEN_ARRAY_START, JSON_TOKEN_NULL, JSON_TOKEN_OBJECT_START, lex_peek(), parse_array(), parse_object(), parse_scalar(), and JsonSemAction::semstate.
Referenced by json_count_array_elements(), and parse_array().
|
static |
Definition at line 489 of file json.c.
References check_stack_depth(), JSON_PARSE_OBJECT_NEXT, JSON_PARSE_OBJECT_START, JSON_TOKEN_COMMA, JSON_TOKEN_OBJECT_END, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, lex_accept(), lex_expect(), JsonLexContext::lex_level, lex_peek(), JsonSemAction::object_end, JsonSemAction::object_start, parse_object_field(), report_parse_error(), and JsonSemAction::semstate.
Referenced by parse_array_element(), parse_object_field(), and pg_parse_json().
|
static |
Definition at line 443 of file json.c.
References JSON_PARSE_OBJECT_LABEL, JSON_PARSE_STRING, JSON_TOKEN_ARRAY_START, JSON_TOKEN_COLON, JSON_TOKEN_NULL, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, lex_accept(), lex_expect(), lex_peek(), JsonSemAction::object_field_end, JsonSemAction::object_field_start, parse_array(), parse_object(), parse_scalar(), report_parse_error(), and JsonSemAction::semstate.
Referenced by parse_object().
|
inlinestatic |
Definition at line 407 of file json.c.
References JSON_PARSE_VALUE, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, lex_accept(), lex_peek(), report_parse_error(), JsonSemAction::scalar, JsonSemAction::semstate, and val.
Referenced by parse_array_element(), parse_object_field(), and pg_parse_json().
void pg_parse_json | ( | JsonLexContext * | lex, |
JsonSemAction * | sem | ||
) |
Definition at line 332 of file json.c.
References json_lex(), JSON_PARSE_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_END, JSON_TOKEN_OBJECT_START, lex_expect(), lex_peek(), parse_array(), parse_object(), and parse_scalar().
Referenced by datum_to_jsonb(), each_worker(), elements_worker(), get_json_object_as_hash(), get_worker(), iterate_json_values(), json_array_length(), json_in(), json_object_keys(), json_recv(), json_strip_nulls(), jsonb_from_cstring(), populate_array_json(), populate_recordset_worker(), and transform_json_string_values().
|
static |
Definition at line 1233 of file json.c.
References ereport, errcode(), errdetail(), errmsg(), ERROR, palloc(), report_json_context(), JsonLexContext::token_start, and JsonLexContext::token_terminator.
Referenced by json_lex(), json_lex_number(), and json_lex_string().
|
static |
Definition at line 1262 of file json.c.
References errcontext, JsonLexContext::input, JsonLexContext::input_length, IS_HIGHBIT_SET, JSON_TOKEN_END, palloc(), pg_mblen(), JsonLexContext::token_terminator, and JsonLexContext::token_type.
Referenced by json_lex_string(), report_invalid_token(), and report_parse_error().
|
static |
Definition at line 1126 of file json.c.
References elog, ereport, errcode(), errdetail(), errmsg(), ERROR, JSON_PARSE_ARRAY_NEXT, JSON_PARSE_ARRAY_START, JSON_PARSE_END, JSON_PARSE_OBJECT_COMMA, JSON_PARSE_OBJECT_LABEL, JSON_PARSE_OBJECT_NEXT, JSON_PARSE_OBJECT_START, JSON_PARSE_STRING, JSON_PARSE_VALUE, JSON_TOKEN_END, palloc(), report_json_context(), JsonLexContext::token_start, JsonLexContext::token_terminator, and JsonLexContext::token_type.
Referenced by lex_expect(), parse_object(), parse_object_field(), and parse_scalar().
Datum row_to_json | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1900 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 1916 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 1933 of file json.c.
References cstring_to_text_with_len(), StringInfoData::data, datum_to_json(), ereport, errcode(), errmsg(), ERROR, get_fn_expr_argtype(), InvalidOid, json_categorize_type(), StringInfoData::len, makeStringInfo(), PG_GETARG_DATUM, PG_RETURN_TEXT_P, and val.
|
static |