PostgreSQL Source Code git master
Loading...
Searching...
No Matches
jsonpath.h File Reference
#include "executor/tablefunc.h"
#include "fmgr.h"
#include "nodes/pg_list.h"
#include "nodes/primnodes.h"
#include "utils/jsonb.h"
Include dependency graph for jsonpath.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  JsonPath
 
struct  JsonPathItem
 
struct  JsonPathParseItem
 
struct  JsonPathParseResult
 
struct  JsonPathVariable
 

Macros

#define JSONPATH_VERSION   (0x01)
 
#define JSONPATH_LAX   (0x80000000)
 
#define JSONPATH_HDRSZ   (offsetof(JsonPath, data))
 
#define PG_GETARG_JSONPATH_P(x)   DatumGetJsonPathP(PG_GETARG_DATUM(x))
 
#define PG_GETARG_JSONPATH_P_COPY(x)   DatumGetJsonPathPCopy(PG_GETARG_DATUM(x))
 
#define PG_RETURN_JSONPATH_P(p)   PG_RETURN_POINTER(p)
 
#define jspIsScalar(type)   ((type) >= jpiNull && (type) <= jpiBool)
 
#define JSP_REGEX_ICASE   0x01 /* i flag, case insensitive */
 
#define JSP_REGEX_DOTALL   0x02 /* s flag, dot matches newline */
 
#define JSP_REGEX_MLINE   0x04 /* m flag, ^/$ match at newlines */
 
#define JSP_REGEX_WSPACE   0x08 /* x flag, ignore whitespace in pattern */
 
#define JSP_REGEX_QUOTE   0x10 /* q flag, no special characters */
 
#define jspHasNext(jsp)   ((jsp)->nextPos > 0)
 

Typedefs

typedef enum JsonPathItemType JsonPathItemType
 
typedef struct JsonPathItem JsonPathItem
 
typedef struct JsonPathParseItem JsonPathParseItem
 
typedef struct JsonPathParseResult JsonPathParseResult
 
typedef struct JsonPathVariable JsonPathVariable
 

Enumerations

enum  JsonPathItemType {
  jpiNull = jbvNull , jpiString = jbvString , jpiNumeric = jbvNumeric , jpiBool = jbvBool ,
  jpiAnd , jpiOr , jpiNot , jpiIsUnknown ,
  jpiEqual , jpiNotEqual , jpiLess , jpiGreater ,
  jpiLessOrEqual , jpiGreaterOrEqual , jpiAdd , jpiSub ,
  jpiMul , jpiDiv , jpiMod , jpiPlus ,
  jpiMinus , jpiAnyArray , jpiAnyKey , jpiIndexArray ,
  jpiAny , jpiKey , jpiCurrent , jpiRoot ,
  jpiVariable , jpiFilter , jpiExists , jpiType ,
  jpiSize , jpiAbs , jpiFloor , jpiCeiling ,
  jpiDouble , jpiDatetime , jpiKeyValue , jpiSubscript ,
  jpiLast , jpiStartsWith , jpiLikeRegex , jpiBigint ,
  jpiBoolean , jpiDate , jpiDecimal , jpiInteger ,
  jpiNumber , jpiStringFunc , jpiTime , jpiTimeTz ,
  jpiTimestamp , jpiTimestampTz , jpiStrReplace , jpiStrLower ,
  jpiStrUpper , jpiStrLtrim , jpiStrRtrim , jpiStrBtrim ,
  jpiStrInitcap , jpiStrSplitPart
}
 

Functions

static JsonPathDatumGetJsonPathP (Datum d)
 
static JsonPathDatumGetJsonPathPCopy (Datum d)
 
void jspInit (JsonPathItem *v, JsonPath *js)
 
void jspInitByBuffer (JsonPathItem *v, char *base, int32 pos)
 
bool jspGetNext (JsonPathItem *v, JsonPathItem *a)
 
void jspGetArg (JsonPathItem *v, JsonPathItem *a)
 
void jspGetLeftArg (JsonPathItem *v, JsonPathItem *a)
 
void jspGetRightArg (JsonPathItem *v, JsonPathItem *a)
 
Numeric jspGetNumeric (JsonPathItem *v)
 
bool jspGetBool (JsonPathItem *v)
 
charjspGetString (JsonPathItem *v, int32 *len)
 
bool jspGetArraySubscript (JsonPathItem *v, JsonPathItem *from, JsonPathItem *to, int i)
 
bool jspIsMutable (JsonPath *path, List *varnames, List *varexprs)
 
const charjspOperationName (JsonPathItemType type)
 
JsonPathParseResultparsejsonpath (const char *str, int len, struct Node *escontext)
 
bool jspConvertRegexFlags (uint32 xflags, int *result, struct Node *escontext)
 
bool JsonPathExists (Datum jb, JsonPath *jp, bool *error, List *vars)
 
Datum JsonPathQuery (Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, bool *error, List *vars, const char *column_name)
 
JsonbValueJsonPathValue (Datum jb, JsonPath *jp, bool *empty, bool *error, List *vars, const char *column_name)
 

Variables

PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine
 

Macro Definition Documentation

◆ JSONPATH_HDRSZ

#define JSONPATH_HDRSZ   (offsetof(JsonPath, data))

Definition at line 32 of file jsonpath.h.

◆ JSONPATH_LAX

#define JSONPATH_LAX   (0x80000000)

Definition at line 31 of file jsonpath.h.

◆ JSONPATH_VERSION

#define JSONPATH_VERSION   (0x01)

Definition at line 30 of file jsonpath.h.

◆ JSP_REGEX_DOTALL

#define JSP_REGEX_DOTALL   0x02 /* s flag, dot matches newline */

Definition at line 130 of file jsonpath.h.

◆ JSP_REGEX_ICASE

#define JSP_REGEX_ICASE   0x01 /* i flag, case insensitive */

Definition at line 129 of file jsonpath.h.

◆ JSP_REGEX_MLINE

#define JSP_REGEX_MLINE   0x04 /* m flag, ^/$ match at newlines */

Definition at line 131 of file jsonpath.h.

◆ JSP_REGEX_QUOTE

#define JSP_REGEX_QUOTE   0x10 /* q flag, no special characters */

Definition at line 133 of file jsonpath.h.

◆ JSP_REGEX_WSPACE

#define JSP_REGEX_WSPACE   0x08 /* x flag, ignore whitespace in pattern */

Definition at line 132 of file jsonpath.h.

◆ jspHasNext

#define jspHasNext (   jsp)    ((jsp)->nextPos > 0)

Definition at line 202 of file jsonpath.h.

◆ jspIsScalar

#define jspIsScalar (   type)    ((type) >= jpiNull && (type) <= jpiBool)

Definition at line 50 of file jsonpath.h.

◆ PG_GETARG_JSONPATH_P

#define PG_GETARG_JSONPATH_P (   x)    DatumGetJsonPathP(PG_GETARG_DATUM(x))

Definition at line 46 of file jsonpath.h.

◆ PG_GETARG_JSONPATH_P_COPY

#define PG_GETARG_JSONPATH_P_COPY (   x)    DatumGetJsonPathPCopy(PG_GETARG_DATUM(x))

Definition at line 47 of file jsonpath.h.

◆ PG_RETURN_JSONPATH_P

#define PG_RETURN_JSONPATH_P (   p)    PG_RETURN_POINTER(p)

Definition at line 48 of file jsonpath.h.

Typedef Documentation

◆ JsonPathItem

◆ JsonPathItemType

◆ JsonPathParseItem

Definition at line 223 of file jsonpath.h.

◆ JsonPathParseResult

◆ JsonPathVariable

Enumeration Type Documentation

◆ JsonPathItemType

Enumerator
jpiNull 
jpiString 
jpiNumeric 
jpiBool 
jpiAnd 
jpiOr 
jpiNot 
jpiIsUnknown 
jpiEqual 
jpiNotEqual 
jpiLess 
jpiGreater 
jpiLessOrEqual 
jpiGreaterOrEqual 
jpiAdd 
jpiSub 
jpiMul 
jpiDiv 
jpiMod 
jpiPlus 
jpiMinus 
jpiAnyArray 
jpiAnyKey 
jpiIndexArray 
jpiAny 
jpiKey 
jpiCurrent 
jpiRoot 
jpiVariable 
jpiFilter 
jpiExists 
jpiType 
jpiSize 
jpiAbs 
jpiFloor 
jpiCeiling 
jpiDouble 
jpiDatetime 
jpiKeyValue 
jpiSubscript 
jpiLast 
jpiStartsWith 
jpiLikeRegex 
jpiBigint 
jpiBoolean 
jpiDate 
jpiDecimal 
jpiInteger 
jpiNumber 
jpiStringFunc 
jpiTime 
jpiTimeTz 
jpiTimestamp 
jpiTimestampTz 
jpiStrReplace 
jpiStrLower 
jpiStrUpper 
jpiStrLtrim 
jpiStrRtrim 
jpiStrBtrim 
jpiStrInitcap 
jpiStrSplitPart 

Definition at line 62 of file jsonpath.h.

63{
64 jpiNull = jbvNull, /* NULL literal */
65 jpiString = jbvString, /* string literal */
66 jpiNumeric = jbvNumeric, /* numeric literal */
67 jpiBool = jbvBool, /* boolean literal: TRUE or FALSE */
68 jpiAnd, /* predicate && predicate */
69 jpiOr, /* predicate || predicate */
70 jpiNot, /* ! predicate */
71 jpiIsUnknown, /* (predicate) IS UNKNOWN */
72 jpiEqual, /* expr == expr */
73 jpiNotEqual, /* expr != expr */
74 jpiLess, /* expr < expr */
75 jpiGreater, /* expr > expr */
76 jpiLessOrEqual, /* expr <= expr */
77 jpiGreaterOrEqual, /* expr >= expr */
78 jpiAdd, /* expr + expr */
79 jpiSub, /* expr - expr */
80 jpiMul, /* expr * expr */
81 jpiDiv, /* expr / expr */
82 jpiMod, /* expr % expr */
83 jpiPlus, /* + expr */
84 jpiMinus, /* - expr */
85 jpiAnyArray, /* [*] */
86 jpiAnyKey, /* .* */
87 jpiIndexArray, /* [subscript, ...] */
88 jpiAny, /* .** */
89 jpiKey, /* .key */
90 jpiCurrent, /* @ */
91 jpiRoot, /* $ */
92 jpiVariable, /* $variable */
93 jpiFilter, /* ? (predicate) */
94 jpiExists, /* EXISTS (expr) predicate */
95 jpiType, /* .type() item method */
96 jpiSize, /* .size() item method */
97 jpiAbs, /* .abs() item method */
98 jpiFloor, /* .floor() item method */
99 jpiCeiling, /* .ceiling() item method */
100 jpiDouble, /* .double() item method */
101 jpiDatetime, /* .datetime() item method */
102 jpiKeyValue, /* .keyvalue() item method */
103 jpiSubscript, /* array subscript: 'expr' or 'expr TO expr' */
104 jpiLast, /* LAST array subscript */
105 jpiStartsWith, /* STARTS WITH predicate */
106 jpiLikeRegex, /* LIKE_REGEX predicate */
107 jpiBigint, /* .bigint() item method */
108 jpiBoolean, /* .boolean() item method */
109 jpiDate, /* .date() item method */
110 jpiDecimal, /* .decimal() item method */
111 jpiInteger, /* .integer() item method */
112 jpiNumber, /* .number() item method */
113 jpiStringFunc, /* .string() item method */
114 jpiTime, /* .time() item method */
115 jpiTimeTz, /* .time_tz() item method */
116 jpiTimestamp, /* .timestamp() item method */
117 jpiTimestampTz, /* .timestamp_tz() item method */
118 jpiStrReplace, /* .replace() item method */
119 jpiStrLower, /* .lower() item method */
120 jpiStrUpper, /* .upper() item method */
121 jpiStrLtrim, /* .ltrim() item method */
122 jpiStrRtrim, /* .rtrim() item method */
123 jpiStrBtrim, /* .btrim() item method */
124 jpiStrInitcap, /* .initcap() item method */
125 jpiStrSplitPart, /* .split_part() item method */
@ jbvNumeric
Definition jsonb.h:232
@ jbvBool
Definition jsonb.h:233
@ jbvNull
Definition jsonb.h:230
@ jbvString
Definition jsonb.h:231
JsonPathItemType
Definition jsonpath.h:63
@ jpiAdd
Definition jsonpath.h:78
@ jpiString
Definition jsonpath.h:65
@ jpiAbs
Definition jsonpath.h:97
@ jpiIndexArray
Definition jsonpath.h:87
@ jpiAny
Definition jsonpath.h:88
@ jpiDatetime
Definition jsonpath.h:101
@ jpiStrRtrim
Definition jsonpath.h:122
@ jpiBigint
Definition jsonpath.h:107
@ jpiBool
Definition jsonpath.h:67
@ jpiType
Definition jsonpath.h:95
@ jpiStrUpper
Definition jsonpath.h:120
@ jpiFloor
Definition jsonpath.h:98
@ jpiStrBtrim
Definition jsonpath.h:123
@ jpiAnyArray
Definition jsonpath.h:85
@ jpiExists
Definition jsonpath.h:94
@ jpiSize
Definition jsonpath.h:96
@ jpiStrReplace
Definition jsonpath.h:118
@ jpiSub
Definition jsonpath.h:79
@ jpiSubscript
Definition jsonpath.h:103
@ jpiNotEqual
Definition jsonpath.h:73
@ jpiMul
Definition jsonpath.h:80
@ jpiVariable
Definition jsonpath.h:92
@ jpiTimeTz
Definition jsonpath.h:115
@ jpiNot
Definition jsonpath.h:70
@ jpiDate
Definition jsonpath.h:109
@ jpiGreaterOrEqual
Definition jsonpath.h:77
@ jpiPlus
Definition jsonpath.h:83
@ jpiStrInitcap
Definition jsonpath.h:124
@ jpiDouble
Definition jsonpath.h:100
@ jpiGreater
Definition jsonpath.h:75
@ jpiNumber
Definition jsonpath.h:112
@ jpiStrLtrim
Definition jsonpath.h:121
@ jpiAnd
Definition jsonpath.h:68
@ jpiStartsWith
Definition jsonpath.h:105
@ jpiOr
Definition jsonpath.h:69
@ jpiMod
Definition jsonpath.h:82
@ jpiTimestamp
Definition jsonpath.h:116
@ jpiStrSplitPart
Definition jsonpath.h:125
@ jpiLikeRegex
Definition jsonpath.h:106
@ jpiTimestampTz
Definition jsonpath.h:117
@ jpiInteger
Definition jsonpath.h:111
@ jpiRoot
Definition jsonpath.h:91
@ jpiFilter
Definition jsonpath.h:93
@ jpiNull
Definition jsonpath.h:64
@ jpiLess
Definition jsonpath.h:74
@ jpiCurrent
Definition jsonpath.h:90
@ jpiEqual
Definition jsonpath.h:72
@ jpiKey
Definition jsonpath.h:89
@ jpiDiv
Definition jsonpath.h:81
@ jpiTime
Definition jsonpath.h:114
@ jpiLast
Definition jsonpath.h:104
@ jpiMinus
Definition jsonpath.h:84
@ jpiLessOrEqual
Definition jsonpath.h:76
@ jpiCeiling
Definition jsonpath.h:99
@ jpiIsUnknown
Definition jsonpath.h:71
@ jpiKeyValue
Definition jsonpath.h:102
@ jpiNumeric
Definition jsonpath.h:66
@ jpiStrLower
Definition jsonpath.h:119
@ jpiBoolean
Definition jsonpath.h:108
@ jpiStringFunc
Definition jsonpath.h:113
@ jpiDecimal
Definition jsonpath.h:110
@ jpiAnyKey
Definition jsonpath.h:86

Function Documentation

◆ DatumGetJsonPathP()

static JsonPath * DatumGetJsonPathP ( Datum  d)
inlinestatic

Definition at line 35 of file jsonpath.h.

36{
37 return (JsonPath *) PG_DETOAST_DATUM(d);
38}
#define PG_DETOAST_DATUM(datum)
Definition fmgr.h:240

References PG_DETOAST_DATUM.

Referenced by contain_mutable_functions_walker(), ExecEvalJsonExprPath(), and JsonTableInitPlan().

◆ DatumGetJsonPathPCopy()

static JsonPath * DatumGetJsonPathPCopy ( Datum  d)
inlinestatic

Definition at line 41 of file jsonpath.h.

42{
43 return (JsonPath *) PG_DETOAST_DATUM_COPY(d);
44}
#define PG_DETOAST_DATUM_COPY(datum)
Definition fmgr.h:242

References PG_DETOAST_DATUM_COPY.

◆ JsonPathExists()

bool JsonPathExists ( Datum  jb,
JsonPath jp,
bool error,
List vars 
)
extern

Definition at line 4202 of file jsonpath_exec.c.

4203{
4205
4206 res = executeJsonPath(jp, vars,
4208 DatumGetJsonbP(jb), !error, NULL, true);
4209
4210 Assert(error || !jperIsError(res));
4211
4212 if (error && jperIsError(res))
4213 *error = true;
4214
4215 return res == jperOk;
4216}
#define Assert(condition)
Definition c.h:943
static Jsonb * DatumGetJsonbP(Datum d)
Definition jsonb.h:401
static JsonbValue * GetJsonPathVar(void *cxt, char *varName, int varNameLen, JsonbValue *baseObject, int *baseObjectId)
#define jperIsError(jper)
JsonPathExecResult
@ jperOk
static int CountJsonPathVars(void *cxt)
static JsonPathExecResult executeJsonPath(JsonPath *path, void *vars, JsonPathGetVarCallback getVar, JsonPathCountVarsCallback countVars, Jsonb *json, bool throwErrors, JsonValueList *result, bool useTz)
static int fb(int x)
static void error(void)

References Assert, CountJsonPathVars(), DatumGetJsonbP(), error(), executeJsonPath(), fb(), GetJsonPathVar(), jperIsError, and jperOk.

Referenced by ExecEvalJsonExprPath().

◆ JsonPathQuery()

Datum JsonPathQuery ( Datum  jb,
JsonPath jp,
JsonWrapper  wrapper,
bool empty,
bool error,
List vars,
const char column_name 
)
extern

Definition at line 4225 of file jsonpath_exec.c.

4228{
4229 bool wrap;
4230 JsonValueList found;
4232
4233 JsonValueListInit(&found);
4234
4235 res = executeJsonPath(jp, vars,
4237 DatumGetJsonbP(jb), !error, &found, true);
4238 Assert(error || !jperIsError(res));
4239 if (error && jperIsError(res))
4240 {
4241 *error = true;
4242 *empty = false;
4243 return (Datum) 0;
4244 }
4245
4246 /*
4247 * Determine whether to wrap the result in a JSON array or not.
4248 *
4249 * If the returned JsonValueList is empty, no wrapping is necessary.
4250 *
4251 * If the wrapper mode is JSW_NONE or JSW_UNSPEC, wrapping is explicitly
4252 * disabled. This enforces a WITHOUT WRAPPER clause, which is also the
4253 * default when no WRAPPER clause is specified.
4254 *
4255 * If the mode is JSW_UNCONDITIONAL, wrapping is enforced regardless of
4256 * the number of SQL/JSON items, enforcing a WITH WRAPPER or WITH
4257 * UNCONDITIONAL WRAPPER clause.
4258 *
4259 * For JSW_CONDITIONAL, wrapping occurs only if there is more than one
4260 * SQL/JSON item in the list, enforcing a WITH CONDITIONAL WRAPPER clause.
4261 */
4262 if (JsonValueListIsEmpty(&found))
4263 wrap = false;
4264 else if (wrapper == JSW_NONE || wrapper == JSW_UNSPEC)
4265 wrap = false;
4266 else if (wrapper == JSW_UNCONDITIONAL)
4267 wrap = true;
4268 else if (wrapper == JSW_CONDITIONAL)
4270 else
4271 {
4272 elog(ERROR, "unrecognized json wrapper %d", (int) wrapper);
4273 wrap = false;
4274 }
4275
4276 if (wrap)
4278
4279 /* No wrapping means at most one item is expected. */
4281 {
4282 if (error)
4283 {
4284 *error = true;
4285 return (Datum) 0;
4286 }
4287
4288 if (column_name)
4289 ereport(ERROR,
4291 errmsg("JSON path expression for column \"%s\" must return single item when no wrapper is requested",
4292 column_name),
4293 errhint("Use the WITH WRAPPER clause to wrap SQL/JSON items into an array.")));
4294 else
4295 ereport(ERROR,
4297 errmsg("JSON path expression in JSON_QUERY must return single item when no wrapper is requested"),
4298 errhint("Use the WITH WRAPPER clause to wrap SQL/JSON items into an array.")));
4299 }
4300
4301 if (!JsonValueListIsEmpty(&found))
4303
4304 *empty = true;
4305 return PointerGetDatum(NULL);
4306}
int errcode(int sqlerrcode)
Definition elog.c:874
int errhint(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
static Datum JsonbPGetDatum(const Jsonb *p)
Definition jsonb.h:413
Jsonb * JsonbValueToJsonb(JsonbValue *val)
Definition jsonb_util.c:96
static bool JsonValueListIsEmpty(const JsonValueList *jvl)
static void JsonValueListInit(JsonValueList *jvl)
static JsonbValue * JsonValueListHead(JsonValueList *jvl)
static bool JsonValueListHasMultipleItems(const JsonValueList *jvl)
static JsonbValue * wrapItemsInArray(JsonValueList *items)
static char * errmsg
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
uint64_t Datum
Definition postgres.h:70
@ JSW_UNCONDITIONAL
Definition primnodes.h:1781
@ JSW_CONDITIONAL
Definition primnodes.h:1780
@ JSW_UNSPEC
Definition primnodes.h:1778
@ JSW_NONE
Definition primnodes.h:1779

References Assert, CountJsonPathVars(), DatumGetJsonbP(), elog, ereport, errcode(), errhint(), errmsg, ERROR, error(), executeJsonPath(), fb(), GetJsonPathVar(), jperIsError, JsonbPGetDatum(), JsonbValueToJsonb(), JsonValueListHasMultipleItems(), JsonValueListHead(), JsonValueListInit(), JsonValueListIsEmpty(), JSW_CONDITIONAL, JSW_NONE, JSW_UNCONDITIONAL, JSW_UNSPEC, PointerGetDatum(), and wrapItemsInArray().

Referenced by ExecEvalJsonExprPath().

◆ JsonPathValue()

JsonbValue * JsonPathValue ( Datum  jb,
JsonPath jp,
bool empty,
bool error,
List vars,
const char column_name 
)
extern

Definition at line 4315 of file jsonpath_exec.c.

4317{
4318 JsonbValue *res;
4319 JsonValueList found;
4321
4322 JsonValueListInit(&found);
4323
4326 !error, &found, true);
4327
4329
4330 if (error && jperIsError(jper))
4331 {
4332 *error = true;
4333 *empty = false;
4334 return NULL;
4335 }
4336
4337 *empty = JsonValueListIsEmpty(&found);
4338
4339 if (*empty)
4340 return NULL;
4341
4342 /* JSON_VALUE expects to get only singletons. */
4344 {
4345 if (error)
4346 {
4347 *error = true;
4348 return NULL;
4349 }
4350
4351 if (column_name)
4352 ereport(ERROR,
4354 errmsg("JSON path expression for column \"%s\" must return single scalar item",
4355 column_name)));
4356 else
4357 ereport(ERROR,
4359 errmsg("JSON path expression in JSON_VALUE must return single scalar item")));
4360 }
4361
4362 res = copyJsonbValue(JsonValueListHead(&found));
4363 if (res->type == jbvBinary && JsonContainerIsScalar(res->val.binary.data))
4364 JsonbExtractScalar(res->val.binary.data, res);
4365
4366 /* JSON_VALUE expects to get only scalars. */
4367 if (!IsAJsonbScalar(res))
4368 {
4369 if (error)
4370 {
4371 *error = true;
4372 return NULL;
4373 }
4374
4375 if (column_name)
4376 ereport(ERROR,
4378 errmsg("JSON path expression for column \"%s\" must return single scalar item",
4379 column_name)));
4380 else
4381 ereport(ERROR,
4383 errmsg("JSON path expression in JSON_VALUE must return single scalar item")));
4384 }
4385
4386 if (res->type == jbvNull)
4387 return NULL;
4388
4389 return res;
4390}
#define PG_USED_FOR_ASSERTS_ONLY
Definition c.h:249
bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)
Definition jsonb.c:1749
@ jbvBinary
Definition jsonb.h:238
#define JsonContainerIsScalar(jc)
Definition jsonb.h:209
#define IsAJsonbScalar(jsonbval)
Definition jsonb.h:299
static JsonbValue * copyJsonbValue(JsonbValue *src)
enum jbvType type
Definition jsonb.h:257
char * val
Definition jsonb.h:266

References Assert, copyJsonbValue(), CountJsonPathVars(), DatumGetJsonbP(), ereport, errcode(), errmsg, ERROR, error(), executeJsonPath(), fb(), GetJsonPathVar(), IsAJsonbScalar, jbvBinary, jbvNull, jperIsError, JsonbExtractScalar(), JsonContainerIsScalar, JsonValueListHasMultipleItems(), JsonValueListHead(), JsonValueListInit(), JsonValueListIsEmpty(), PG_USED_FOR_ASSERTS_ONLY, JsonbValue::type, and JsonbValue::val.

Referenced by ExecEvalJsonExprPath().

◆ jspConvertRegexFlags()

bool jspConvertRegexFlags ( uint32  xflags,
int result,
struct Node escontext 
)
extern

Referenced by executeLikeRegex().

◆ jspGetArg()

void jspGetArg ( JsonPathItem v,
JsonPathItem a 
)
extern

Definition at line 1167 of file jsonpath.c.

1168{
1169 Assert(v->type == jpiNot ||
1170 v->type == jpiIsUnknown ||
1171 v->type == jpiPlus ||
1172 v->type == jpiMinus ||
1173 v->type == jpiFilter ||
1174 v->type == jpiExists ||
1175 v->type == jpiDatetime ||
1176 v->type == jpiTime ||
1177 v->type == jpiTimeTz ||
1178 v->type == jpiTimestamp ||
1179 v->type == jpiTimestampTz ||
1180 v->type == jpiStrLtrim ||
1181 v->type == jpiStrRtrim ||
1182 v->type == jpiStrBtrim);
1183
1184 jspInitByBuffer(a, v->base, v->content.arg);
1185}
int a
Definition isn.c:73
void jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
Definition jsonpath.c:1068
union JsonPathItem::@152 content
char * base
Definition jsonpath.h:154
JsonPathItemType type
Definition jsonpath.h:145

References a, JsonPathItem::arg, Assert, JsonPathItem::base, JsonPathItem::content, jpiDatetime, jpiExists, jpiFilter, jpiIsUnknown, jpiMinus, jpiNot, jpiPlus, jpiStrBtrim, jpiStrLtrim, jpiStrRtrim, jpiTime, jpiTimestamp, jpiTimestampTz, jpiTimeTz, jspInitByBuffer(), and JsonPathItem::type.

Referenced by executeBoolItem(), executeDateTimeMethod(), executeItemOptUnwrapTarget(), executeStringInternalMethod(), executeUnaryArithmExpr(), extract_jsp_bool_expr(), extract_jsp_path_expr_nodes(), jspIsMutableWalker(), and printJsonPathItem().

◆ jspGetArraySubscript()

bool jspGetArraySubscript ( JsonPathItem v,
JsonPathItem from,
JsonPathItem to,
int  i 
)
extern

Definition at line 1339 of file jsonpath.c.

1341{
1342 Assert(v->type == jpiIndexArray);
1343
1344 jspInitByBuffer(from, v->base, v->content.array.elems[i].from);
1345
1346 if (!v->content.array.elems[i].to)
1347 return false;
1348
1349 jspInitByBuffer(to, v->base, v->content.array.elems[i].to);
1350
1351 return true;
1352}
int i
Definition isn.c:77
struct JsonPathItem::@152::@154::@158 * elems
struct JsonPathItem::@152::@154 array

References JsonPathItem::array, Assert, JsonPathItem::base, JsonPathItem::content, JsonPathItem::elems, i, jpiIndexArray, jspInitByBuffer(), and JsonPathItem::type.

Referenced by executeItemOptUnwrapTarget(), jspIsMutableWalker(), and printJsonPathItem().

◆ jspGetBool()

bool jspGetBool ( JsonPathItem v)
extern

Definition at line 1311 of file jsonpath.c.

1312{
1313 Assert(v->type == jpiBool);
1314
1315 return (bool) *v->content.value.data;
1316}
char * data
Definition jsonpath.h:188
struct JsonPathItem::@152::@156 value

References Assert, JsonPathItem::content, JsonPathItem::data, jpiBool, JsonPathItem::type, and JsonPathItem::value.

Referenced by getJsonPathItem(), and printJsonPathItem().

◆ jspGetLeftArg()

void jspGetLeftArg ( JsonPathItem v,
JsonPathItem a 
)
extern

◆ jspGetNext()

bool jspGetNext ( JsonPathItem v,
JsonPathItem a 
)
extern

Definition at line 1188 of file jsonpath.c.

1189{
1190 if (jspHasNext(v))
1191 {
1192 Assert(v->type == jpiNull ||
1193 v->type == jpiString ||
1194 v->type == jpiNumeric ||
1195 v->type == jpiBool ||
1196 v->type == jpiAnd ||
1197 v->type == jpiOr ||
1198 v->type == jpiNot ||
1199 v->type == jpiIsUnknown ||
1200 v->type == jpiEqual ||
1201 v->type == jpiNotEqual ||
1202 v->type == jpiLess ||
1203 v->type == jpiGreater ||
1204 v->type == jpiLessOrEqual ||
1205 v->type == jpiGreaterOrEqual ||
1206 v->type == jpiAdd ||
1207 v->type == jpiSub ||
1208 v->type == jpiMul ||
1209 v->type == jpiDiv ||
1210 v->type == jpiMod ||
1211 v->type == jpiPlus ||
1212 v->type == jpiMinus ||
1213 v->type == jpiAnyArray ||
1214 v->type == jpiAnyKey ||
1215 v->type == jpiIndexArray ||
1216 v->type == jpiAny ||
1217 v->type == jpiKey ||
1218 v->type == jpiCurrent ||
1219 v->type == jpiRoot ||
1220 v->type == jpiVariable ||
1221 v->type == jpiFilter ||
1222 v->type == jpiExists ||
1223 v->type == jpiType ||
1224 v->type == jpiSize ||
1225 v->type == jpiAbs ||
1226 v->type == jpiFloor ||
1227 v->type == jpiCeiling ||
1228 v->type == jpiDouble ||
1229 v->type == jpiDatetime ||
1230 v->type == jpiKeyValue ||
1231 v->type == jpiLast ||
1232 v->type == jpiStartsWith ||
1233 v->type == jpiLikeRegex ||
1234 v->type == jpiBigint ||
1235 v->type == jpiBoolean ||
1236 v->type == jpiDate ||
1237 v->type == jpiDecimal ||
1238 v->type == jpiInteger ||
1239 v->type == jpiNumber ||
1240 v->type == jpiStringFunc ||
1241 v->type == jpiTime ||
1242 v->type == jpiTimeTz ||
1243 v->type == jpiTimestamp ||
1244 v->type == jpiTimestampTz ||
1245 v->type == jpiStrReplace ||
1246 v->type == jpiStrLower ||
1247 v->type == jpiStrUpper ||
1248 v->type == jpiStrLtrim ||
1249 v->type == jpiStrRtrim ||
1250 v->type == jpiStrBtrim ||
1251 v->type == jpiStrInitcap ||
1252 v->type == jpiStrSplitPart);
1253
1254 if (a)
1255 jspInitByBuffer(a, v->base, v->nextPos);
1256 return true;
1257 }
1258
1259 return false;
1260}
#define jspHasNext(jsp)
Definition jsonpath.h:202
int32 nextPos
Definition jsonpath.h:148

References a, Assert, JsonPathItem::base, jpiAbs, jpiAdd, jpiAnd, jpiAny, jpiAnyArray, jpiAnyKey, jpiBigint, jpiBool, jpiBoolean, jpiCeiling, jpiCurrent, jpiDate, jpiDatetime, jpiDecimal, jpiDiv, jpiDouble, jpiEqual, jpiExists, jpiFilter, jpiFloor, jpiGreater, jpiGreaterOrEqual, jpiIndexArray, jpiInteger, jpiIsUnknown, jpiKey, jpiKeyValue, jpiLast, jpiLess, jpiLessOrEqual, jpiLikeRegex, jpiMinus, jpiMod, jpiMul, jpiNot, jpiNotEqual, jpiNull, jpiNumber, jpiNumeric, jpiOr, jpiPlus, jpiRoot, jpiSize, jpiStartsWith, jpiStrBtrim, jpiString, jpiStringFunc, jpiStrInitcap, jpiStrLower, jpiStrLtrim, jpiStrReplace, jpiStrRtrim, jpiStrSplitPart, jpiStrUpper, jpiSub, jpiTime, jpiTimestamp, jpiTimestampTz, jpiTimeTz, jpiType, jpiVariable, jspHasNext, jspInitByBuffer(), JsonPathItem::nextPos, and JsonPathItem::type.

Referenced by appendBoolResult(), executeBinaryArithmExpr(), executeDateTimeMethod(), executeItemOptUnwrapTarget(), executeKeyValueMethod(), executeNextItem(), executeNumericItemMethod(), executeStringInternalMethod(), executeUnaryArithmExpr(), extract_jsp_path_expr_nodes(), jspIsMutableWalker(), and printJsonPathItem().

◆ jspGetNumeric()

◆ jspGetRightArg()

◆ jspGetString()

◆ jspInit()

void jspInit ( JsonPathItem v,
JsonPath js 
)
extern

Definition at line 1058 of file jsonpath.c.

1059{
1061 jspInitByBuffer(v, js->data, 0);
1062}
#define JSONPATH_VERSION
Definition jsonpath.h:30
#define JSONPATH_LAX
Definition jsonpath.h:31
char data[FLEXIBLE_ARRAY_MEMBER]
Definition jsonpath.h:27
uint32 header
Definition jsonpath.h:26

References Assert, JsonPath::data, JsonPath::header, JSONPATH_LAX, JSONPATH_VERSION, and jspInitByBuffer().

Referenced by executeJsonPath(), extract_jsp_query(), jsonPathToCstring(), and jspIsMutable().

◆ jspInitByBuffer()

void jspInitByBuffer ( JsonPathItem v,
char base,
int32  pos 
)
extern

Definition at line 1068 of file jsonpath.c.

1069{
1070 v->base = base + pos;
1071
1072 read_byte(v->type, base, pos);
1073 pos = INTALIGN((uintptr_t) (base + pos)) - (uintptr_t) base;
1074 read_int32(v->nextPos, base, pos);
1075
1076 switch (v->type)
1077 {
1078 case jpiNull:
1079 case jpiRoot:
1080 case jpiCurrent:
1081 case jpiAnyArray:
1082 case jpiAnyKey:
1083 case jpiType:
1084 case jpiSize:
1085 case jpiAbs:
1086 case jpiFloor:
1087 case jpiCeiling:
1088 case jpiDouble:
1089 case jpiKeyValue:
1090 case jpiLast:
1091 case jpiBigint:
1092 case jpiBoolean:
1093 case jpiDate:
1094 case jpiInteger:
1095 case jpiNumber:
1096 case jpiStringFunc:
1097 case jpiStrLower:
1098 case jpiStrUpper:
1099 case jpiStrInitcap:
1100 break;
1101 case jpiString:
1102 case jpiKey:
1103 case jpiVariable:
1104 read_int32(v->content.value.datalen, base, pos);
1106 case jpiNumeric:
1107 case jpiBool:
1108 v->content.value.data = base + pos;
1109 break;
1110 case jpiAnd:
1111 case jpiOr:
1112 case jpiEqual:
1113 case jpiNotEqual:
1114 case jpiLess:
1115 case jpiGreater:
1116 case jpiLessOrEqual:
1117 case jpiGreaterOrEqual:
1118 case jpiAdd:
1119 case jpiSub:
1120 case jpiMul:
1121 case jpiDiv:
1122 case jpiMod:
1123 case jpiStartsWith:
1124 case jpiDecimal:
1125 case jpiStrReplace:
1126 case jpiStrSplitPart:
1127 read_int32(v->content.args.left, base, pos);
1128 read_int32(v->content.args.right, base, pos);
1129 break;
1130 case jpiNot:
1131 case jpiIsUnknown:
1132 case jpiExists:
1133 case jpiPlus:
1134 case jpiMinus:
1135 case jpiFilter:
1136 case jpiDatetime:
1137 case jpiTime:
1138 case jpiTimeTz:
1139 case jpiTimestamp:
1140 case jpiTimestampTz:
1141 case jpiStrLtrim:
1142 case jpiStrRtrim:
1143 case jpiStrBtrim:
1144 read_int32(v->content.arg, base, pos);
1145 break;
1146 case jpiIndexArray:
1147 read_int32(v->content.array.nelems, base, pos);
1148 read_int32_n(v->content.array.elems, base, pos,
1149 v->content.array.nelems * 2);
1150 break;
1151 case jpiAny:
1152 read_int32(v->content.anybounds.first, base, pos);
1153 read_int32(v->content.anybounds.last, base, pos);
1154 break;
1155 case jpiLikeRegex:
1156 read_int32(v->content.like_regex.flags, base, pos);
1157 read_int32(v->content.like_regex.expr, base, pos);
1158 read_int32(v->content.like_regex.patternlen, base, pos);
1159 v->content.like_regex.pattern = base + pos;
1160 break;
1161 default:
1162 elog(ERROR, "unrecognized jsonpath item type: %d", v->type);
1163 }
1164}
#define INTALIGN(LEN)
Definition c.h:893
#define pg_fallthrough
Definition c.h:161
#define read_byte(v, b, p)
Definition jsonpath.c:1039
#define read_int32_n(v, b, p, n)
Definition jsonpath.c:1049
#define read_int32(v, b, p)
Definition jsonpath.c:1044
struct JsonPathItem::@152::@155 anybounds
uint32 first
Definition jsonpath.h:182
int32 nelems
Definition jsonpath.h:171
uint32 flags
Definition jsonpath.h:197
struct JsonPathItem::@152::@157 like_regex
uint32 last
Definition jsonpath.h:183
int32 patternlen
Definition jsonpath.h:196
char * pattern
Definition jsonpath.h:195

References JsonPathItem::anybounds, JsonPathItem::arg, JsonPathItem::args, JsonPathItem::array, JsonPathItem::base, JsonPathItem::content, JsonPathItem::data, JsonPathItem::datalen, JsonPathItem::elems, elog, ERROR, JsonPathItem::expr, fb(), JsonPathItem::first, JsonPathItem::flags, INTALIGN, jpiAbs, jpiAdd, jpiAnd, jpiAny, jpiAnyArray, jpiAnyKey, jpiBigint, jpiBool, jpiBoolean, jpiCeiling, jpiCurrent, jpiDate, jpiDatetime, jpiDecimal, jpiDiv, jpiDouble, jpiEqual, jpiExists, jpiFilter, jpiFloor, jpiGreater, jpiGreaterOrEqual, jpiIndexArray, jpiInteger, jpiIsUnknown, jpiKey, jpiKeyValue, jpiLast, jpiLess, jpiLessOrEqual, jpiLikeRegex, jpiMinus, jpiMod, jpiMul, jpiNot, jpiNotEqual, jpiNull, jpiNumber, jpiNumeric, jpiOr, jpiPlus, jpiRoot, jpiSize, jpiStartsWith, jpiStrBtrim, jpiString, jpiStringFunc, jpiStrInitcap, jpiStrLower, jpiStrLtrim, jpiStrReplace, jpiStrRtrim, jpiStrSplitPart, jpiStrUpper, jpiSub, jpiTime, jpiTimestamp, jpiTimestampTz, jpiTimeTz, jpiType, jpiVariable, JsonPathItem::last, JsonPathItem::left, JsonPathItem::like_regex, JsonPathItem::nelems, JsonPathItem::nextPos, JsonPathItem::pattern, JsonPathItem::patternlen, pg_fallthrough, read_byte, read_int32, read_int32_n, JsonPathItem::right, JsonPathItem::type, and JsonPathItem::value.

Referenced by executeBoolItem(), jspGetArg(), jspGetArraySubscript(), jspGetLeftArg(), jspGetNext(), jspGetRightArg(), jspInit(), jspIsMutableWalker(), and printJsonPathItem().

◆ jspIsMutable()

bool jspIsMutable ( JsonPath path,
List varnames,
List varexprs 
)
extern

Definition at line 1381 of file jsonpath.c.

1382{
1383 struct JsonPathMutableContext cxt;
1385
1386 cxt.varnames = varnames;
1387 cxt.varexprs = varexprs;
1388 cxt.current = jpdsNonDateTime;
1389 cxt.lax = (path->header & JSONPATH_LAX) != 0;
1390 cxt.mutable = false;
1391
1392 jspInit(&jpi, path);
1393 (void) jspIsMutableWalker(&jpi, &cxt);
1394
1395 return cxt.mutable;
1396}
static enum JsonPathDatatypeStatus jspIsMutableWalker(JsonPathItem *jpi, struct JsonPathMutableContext *cxt)
Definition jsonpath.c:1402
void jspInit(JsonPathItem *v, JsonPath *js)
Definition jsonpath.c:1058
@ jpdsNonDateTime
Definition jsonpath.c:1357

References JsonPathMutableContext::current, fb(), JsonPath::header, jpdsNonDateTime, JSONPATH_LAX, jspInit(), jspIsMutableWalker(), JsonPathMutableContext::lax, JsonPathMutableContext::mutable, JsonPathMutableContext::varexprs, and JsonPathMutableContext::varnames.

Referenced by contain_mutable_functions_walker().

◆ jspOperationName()

const char * jspOperationName ( JsonPathItemType  type)
extern

Definition at line 905 of file jsonpath.c.

906{
907 switch (type)
908 {
909 case jpiAnd:
910 return "&&";
911 case jpiOr:
912 return "||";
913 case jpiEqual:
914 return "==";
915 case jpiNotEqual:
916 return "!=";
917 case jpiLess:
918 return "<";
919 case jpiGreater:
920 return ">";
921 case jpiLessOrEqual:
922 return "<=";
924 return ">=";
925 case jpiAdd:
926 case jpiPlus:
927 return "+";
928 case jpiSub:
929 case jpiMinus:
930 return "-";
931 case jpiMul:
932 return "*";
933 case jpiDiv:
934 return "/";
935 case jpiMod:
936 return "%";
937 case jpiType:
938 return "type";
939 case jpiSize:
940 return "size";
941 case jpiAbs:
942 return "abs";
943 case jpiFloor:
944 return "floor";
945 case jpiCeiling:
946 return "ceiling";
947 case jpiDouble:
948 return "double";
949 case jpiDatetime:
950 return "datetime";
951 case jpiKeyValue:
952 return "keyvalue";
953 case jpiStartsWith:
954 return "starts with";
955 case jpiLikeRegex:
956 return "like_regex";
957 case jpiBigint:
958 return "bigint";
959 case jpiBoolean:
960 return "boolean";
961 case jpiDate:
962 return "date";
963 case jpiDecimal:
964 return "decimal";
965 case jpiInteger:
966 return "integer";
967 case jpiNumber:
968 return "number";
969 case jpiStringFunc:
970 return "string";
971 case jpiTime:
972 return "time";
973 case jpiTimeTz:
974 return "time_tz";
975 case jpiTimestamp:
976 return "timestamp";
977 case jpiTimestampTz:
978 return "timestamp_tz";
979 case jpiStrReplace:
980 return "replace";
981 case jpiStrLower:
982 return "lower";
983 case jpiStrUpper:
984 return "upper";
985 case jpiStrLtrim:
986 return "ltrim";
987 case jpiStrRtrim:
988 return "rtrim";
989 case jpiStrBtrim:
990 return "btrim";
991 case jpiStrInitcap:
992 return "initcap";
993 case jpiStrSplitPart:
994 return "split_part";
995 default:
996 elog(ERROR, "unrecognized jsonpath item type: %d", type);
997 return NULL;
998 }
999}
const char * type

References elog, ERROR, fb(), jpiAbs, jpiAdd, jpiAnd, jpiBigint, jpiBoolean, jpiCeiling, jpiDate, jpiDatetime, jpiDecimal, jpiDiv, jpiDouble, jpiEqual, jpiFloor, jpiGreater, jpiGreaterOrEqual, jpiInteger, jpiKeyValue, jpiLess, jpiLessOrEqual, jpiLikeRegex, jpiMinus, jpiMod, jpiMul, jpiNotEqual, jpiNumber, jpiOr, jpiPlus, jpiSize, jpiStartsWith, jpiStrBtrim, jpiStringFunc, jpiStrInitcap, jpiStrLower, jpiStrLtrim, jpiStrReplace, jpiStrRtrim, jpiStrSplitPart, jpiStrUpper, jpiSub, jpiTime, jpiTimestamp, jpiTimestampTz, jpiTimeTz, jpiType, and type.

Referenced by executeBinaryArithmExpr(), executeDateTimeMethod(), executeItemOptUnwrapTarget(), executeKeyValueMethod(), executeNumericItemMethod(), executeStringInternalMethod(), executeUnaryArithmExpr(), and printJsonPathItem().

◆ parsejsonpath()

JsonPathParseResult * parsejsonpath ( const char str,
int  len,
struct Node escontext 
)
extern

Definition at line 536 of file jsonpath_scan.l.

537{
539 yyscan_t scanner;
541
542 if (jsonpath_yylex_init(&scanner) != 0)
543 elog(ERROR, "yylex_init() failed: %m");
544
545 yyset_extra(&yyext, scanner);
546
547 if (len <= 0)
548 len = strlen(str);
549
550 jsonpath_yy_scan_bytes(str, len, scanner);
551
552 if (jsonpath_yyparse(&parseresult, escontext, scanner) != 0)
553 jsonpath_yyerror(NULL, escontext, scanner, "invalid input"); /* shouldn't happen */
554
555 jsonpath_yylex_destroy(scanner);
556
557 return parseresult;
558}
void * yyscan_t
Definition cubedata.h:65
const char * str
TestSpec parseresult
int jsonpath_yyparse(JsonPathParseResult **result, struct Node *escontext, yyscan_t yyscanner)
void jsonpath_yyerror(JsonPathParseResult **result, struct Node *escontext, yyscan_t yyscanner, const char *message)

References elog, ERROR, fb(), jsonpath_yyerror(), jsonpath_yyparse(), len, parseresult, and str.

Referenced by jsonPathFromCstring().

Variable Documentation

◆ JsonbTableRoutine

PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine
extern

Definition at line 400 of file jsonpath_exec.c.

401{
402 .InitOpaque = JsonTableInitOpaque,
403 .SetDocument = JsonTableSetDocument,
404 .SetNamespace = NULL,
405 .SetRowFilter = NULL,
406 .SetColumnFilter = NULL,
407 .FetchRow = JsonTableFetchRow,
408 .GetValue = JsonTableGetValue,
409 .DestroyOpaque = JsonTableDestroyOpaque
410};
static void JsonTableSetDocument(TableFuncScanState *state, Datum value)
static void JsonTableDestroyOpaque(TableFuncScanState *state)
static void JsonTableInitOpaque(TableFuncScanState *state, int natts)
static Datum JsonTableGetValue(TableFuncScanState *state, int colnum, Oid typid, int32 typmod, bool *isnull)
static bool JsonTableFetchRow(TableFuncScanState *state)

Referenced by ExecInitTableFuncScan().