PostgreSQL Source Code git master
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
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   JsonPathVariable
 

Macros

#define  JSONPATH_VERSION   (0x01)
 
#define  JSONPATH_LAX   (0x80000000)
 
#define  JSONPATH_HDRSZ   (offsetof(JsonPath, data))
 
 
 
 
#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 struct JsonPathItem  JsonPathItem
 
 
 
 

Enumerations

 

Functions

 
 
void  jspInit (JsonPathItem *v, JsonPath *js)
 
void  jspInitByBuffer (JsonPathItem *v, char *base, int32 pos)
 
 
 
 
 
 
 
 
 
bool  jspIsMutable (JsonPath *path, List *varnames, List *varexprs)
 
 
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

 

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 122 of file jsonpath.h.

JSP_REGEX_ICASE

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

Definition at line 121 of file jsonpath.h.

JSP_REGEX_MLINE

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

Definition at line 123 of file jsonpath.h.

JSP_REGEX_QUOTE

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

Definition at line 125 of file jsonpath.h.

JSP_REGEX_WSPACE

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

Definition at line 124 of file jsonpath.h.

jspHasNext

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

Definition at line 194 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

typedef struct JsonPathItem JsonPathItem

JsonPathItemType

JsonPathParseItem

Definition at line 215 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 

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 */
@ jbvNumeric
Definition: jsonb.h:230
@ jbvBool
Definition: jsonb.h:231
@ jbvNull
Definition: jsonb.h:228
@ jbvString
Definition: jsonb.h:229
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
@ jpiBigint
Definition: jsonpath.h:107
@ jpiBool
Definition: jsonpath.h:67
@ jpiType
Definition: jsonpath.h:95
@ jpiFloor
Definition: jsonpath.h:98
@ jpiAnyArray
Definition: jsonpath.h:85
@ jpiExists
Definition: jsonpath.h:94
@ jpiSize
Definition: jsonpath.h:96
@ 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
@ jpiDouble
Definition: jsonpath.h:100
@ jpiGreater
Definition: jsonpath.h:75
@ jpiNumber
Definition: jsonpath.h:112
@ 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
@ 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
@ 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
Definition: jsonpath.h:24

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,
JsonPathjp,
bool *  error,
Listvars 
)

Definition at line 3889 of file jsonpath_exec.c.

3890{
3892
3893 res = executeJsonPath(jp, vars,
3895 DatumGetJsonbP(jb), !error, NULL, true);
3896
3897 Assert(error || !jperIsError(res));
3898
3899 if (error && jperIsError(res))
3900 *error = true;
3901
3902 return res == jperOk;
3903}
Assert(PointerIsAligned(start, uint64))
static Jsonb * DatumGetJsonbP(Datum d)
Definition: jsonb.h:374
static JsonbValue * GetJsonPathVar(void *cxt, char *varName, int varNameLen, JsonbValue *baseObject, int *baseObjectId)
#define jperIsError(jper)
Definition: jsonpath_exec.c:142
JsonPathExecResult
Definition: jsonpath_exec.c:136
@ jperOk
Definition: jsonpath_exec.c:137
static int CountJsonPathVars(void *cxt)
static JsonPathExecResult executeJsonPath(JsonPath *path, void *vars, JsonPathGetVarCallback getVar, JsonPathCountVarsCallback countVars, Jsonb *json, bool throwErrors, JsonValueList *result, bool useTz)
Definition: jsonpath_exec.c:678
static void error(void)
Definition: sql-dyntest.c:147
Definition: regcomp.c:282

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

Referenced by ExecEvalJsonExprPath().

JsonPathQuery()

Datum JsonPathQuery ( Datum  jb,
JsonPathjp,
JsonWrapper  wrapper,
bool *  empty,
bool *  error,
Listvars,
const char *  column_name 
)

Definition at line 3912 of file jsonpath_exec.c.

3915{
3916 JsonbValue *singleton;
3917 bool wrap;
3918 JsonValueList found = {0};
3920 int count;
3921
3922 res = executeJsonPath(jp, vars,
3924 DatumGetJsonbP(jb), !error, &found, true);
3925 Assert(error || !jperIsError(res));
3926 if (error && jperIsError(res))
3927 {
3928 *error = true;
3929 *empty = false;
3930 return (Datum) 0;
3931 }
3932
3933 /*
3934 * Determine whether to wrap the result in a JSON array or not.
3935 *
3936 * First, count the number of SQL/JSON items in the returned
3937 * JsonValueList. If the list is empty (singleton == NULL), no wrapping is
3938 * necessary.
3939 *
3940 * If the wrapper mode is JSW_NONE or JSW_UNSPEC, wrapping is explicitly
3941 * disabled. This enforces a WITHOUT WRAPPER clause, which is also the
3942 * default when no WRAPPER clause is specified.
3943 *
3944 * If the mode is JSW_UNCONDITIONAL, wrapping is enforced regardless of
3945 * the number of SQL/JSON items, enforcing a WITH WRAPPER or WITH
3946 * UNCONDITIONAL WRAPPER clause.
3947 *
3948 * For JSW_CONDITIONAL, wrapping occurs only if there is more than one
3949 * SQL/JSON item in the list, enforcing a WITH CONDITIONAL WRAPPER clause.
3950 */
3951 count = JsonValueListLength(&found);
3952 singleton = count > 0 ? JsonValueListHead(&found) : NULL;
3953 if (singleton == NULL)
3954 wrap = false;
3955 else if (wrapper == JSW_NONE || wrapper == JSW_UNSPEC)
3956 wrap = false;
3957 else if (wrapper == JSW_UNCONDITIONAL)
3958 wrap = true;
3959 else if (wrapper == JSW_CONDITIONAL)
3960 wrap = count > 1;
3961 else
3962 {
3963 elog(ERROR, "unrecognized json wrapper %d", (int) wrapper);
3964 wrap = false;
3965 }
3966
3967 if (wrap)
3969
3970 /* No wrapping means only one item is expected. */
3971 if (count > 1)
3972 {
3973 if (error)
3974 {
3975 *error = true;
3976 return (Datum) 0;
3977 }
3978
3979 if (column_name)
3980 ereport(ERROR,
3981 (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
3982 errmsg("JSON path expression for column \"%s\" must return single item when no wrapper is requested",
3983 column_name),
3984 errhint("Use the WITH WRAPPER clause to wrap SQL/JSON items into an array.")));
3985 else
3986 ereport(ERROR,
3987 (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
3988 errmsg("JSON path expression in JSON_QUERY must return single item when no wrapper is requested"),
3989 errhint("Use the WITH WRAPPER clause to wrap SQL/JSON items into an array.")));
3990 }
3991
3992 if (singleton)
3993 return JsonbPGetDatum(JsonbValueToJsonb(singleton));
3994
3995 *empty = true;
3996 return PointerGetDatum(NULL);
3997}
int errhint(const char *fmt,...)
Definition: elog.c:1321
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define ereport(elevel,...)
Definition: elog.h:150
static Datum JsonbPGetDatum(const Jsonb *p)
Definition: jsonb.h:386
Jsonb * JsonbValueToJsonb(JsonbValue *val)
Definition: jsonb_util.c:92
static JsonbValue * wrapItemsInArray(const JsonValueList *items)
static int JsonValueListLength(const JsonValueList *jvl)
static JsonbValue * JsonValueListHead(JsonValueList *jvl)
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:332
uint64_t Datum
Definition: postgres.h:70
@ JSW_UNCONDITIONAL
Definition: primnodes.h:1778
@ JSW_CONDITIONAL
Definition: primnodes.h:1777
@ JSW_UNSPEC
Definition: primnodes.h:1775
@ JSW_NONE
Definition: primnodes.h:1776
Definition: jsonb.h:254

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

Referenced by ExecEvalJsonExprPath().

JsonPathValue()

JsonbValue * JsonPathValue ( Datum  jb,
JsonPathjp,
bool *  empty,
bool *  error,
Listvars,
const char *  column_name 
)

Definition at line 4006 of file jsonpath_exec.c.

4008{
4009 JsonbValue *res;
4010 JsonValueList found = {0};
4012 int count;
4013
4015 DatumGetJsonbP(jb),
4016 !error, &found, true);
4017
4018 Assert(error || !jperIsError(jper));
4019
4020 if (error && jperIsError(jper))
4021 {
4022 *error = true;
4023 *empty = false;
4024 return NULL;
4025 }
4026
4027 count = JsonValueListLength(&found);
4028
4029 *empty = (count == 0);
4030
4031 if (*empty)
4032 return NULL;
4033
4034 /* JSON_VALUE expects to get only singletons. */
4035 if (count > 1)
4036 {
4037 if (error)
4038 {
4039 *error = true;
4040 return NULL;
4041 }
4042
4043 if (column_name)
4044 ereport(ERROR,
4045 (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
4046 errmsg("JSON path expression for column \"%s\" must return single scalar item",
4047 column_name)));
4048 else
4049 ereport(ERROR,
4050 (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
4051 errmsg("JSON path expression in JSON_VALUE must return single scalar item")));
4052 }
4053
4054 res = JsonValueListHead(&found);
4055 if (res->type == jbvBinary && JsonContainerIsScalar(res->val.binary.data))
4056 JsonbExtractScalar(res->val.binary.data, res);
4057
4058 /* JSON_VALUE expects to get only scalars. */
4059 if (!IsAJsonbScalar(res))
4060 {
4061 if (error)
4062 {
4063 *error = true;
4064 return NULL;
4065 }
4066
4067 if (column_name)
4068 ereport(ERROR,
4069 (errcode(ERRCODE_SQL_JSON_SCALAR_REQUIRED),
4070 errmsg("JSON path expression for column \"%s\" must return single scalar item",
4071 column_name)));
4072 else
4073 ereport(ERROR,
4074 (errcode(ERRCODE_SQL_JSON_SCALAR_REQUIRED),
4075 errmsg("JSON path expression in JSON_VALUE must return single scalar item")));
4076 }
4077
4078 if (res->type == jbvNull)
4079 return NULL;
4080
4081 return res;
4082}
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:223
bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)
Definition: jsonb.c:1968
@ jbvBinary
Definition: jsonb.h:236
#define JsonContainerIsScalar(jc)
Definition: jsonb.h:207
#define IsAJsonbScalar(jsonbval)
Definition: jsonb.h:297
enum jbvType type
Definition: jsonb.h:255
char * val
Definition: jsonb.h:264

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

Referenced by ExecEvalJsonExprPath().

jspConvertRegexFlags()

bool jspConvertRegexFlags ( uint32  xflags,
int *  result,
struct Nodeescontext 
)

Referenced by executeLikeRegex().

jspGetArg()

void jspGetArg ( JsonPathItemv,
JsonPathItema 
)

Definition at line 1081 of file jsonpath.c.

1082{
1083 Assert(v->type == jpiNot ||
1084 v->type == jpiIsUnknown ||
1085 v->type == jpiPlus ||
1086 v->type == jpiMinus ||
1087 v->type == jpiFilter ||
1088 v->type == jpiExists ||
1089 v->type == jpiDatetime ||
1090 v->type == jpiTime ||
1091 v->type == jpiTimeTz ||
1092 v->type == jpiTimestamp ||
1093 v->type == jpiTimestampTz);
1094
1095 jspInitByBuffer(a, v->base, v->content.arg);
1096}
a
int a
Definition: isn.c:73
void jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
Definition: jsonpath.c:990
char * base
Definition: jsonpath.h:146
union JsonPathItem::@150 content
int32 arg
Definition: jsonpath.h:158
JsonPathItemType type
Definition: jsonpath.h:137

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

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

jspGetArraySubscript()

bool jspGetArraySubscript ( JsonPathItemv,
JsonPathItemfrom,
JsonPathItemto,
int  i 
)

Definition at line 1238 of file jsonpath.c.

1240{
1241 Assert(v->type == jpiIndexArray);
1242
1243 jspInitByBuffer(from, v->base, v->content.array.elems[i].from);
1244
1245 if (!v->content.array.elems[i].to)
1246 return false;
1247
1248 jspInitByBuffer(to, v->base, v->content.array.elems[i].to);
1249
1250 return true;
1251}
i
int i
Definition: isn.c:77
struct JsonPathItem::@150::@152::@156 * elems
struct JsonPathItem::@150::@152 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 ( JsonPathItemv )

Definition at line 1210 of file jsonpath.c.

1211{
1212 Assert(v->type == jpiBool);
1213
1214 return (bool) *v->content.value.data;
1215}
char * data
Definition: jsonpath.h:180
struct JsonPathItem::@150::@154 value

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

Referenced by getJsonPathItem(), and printJsonPathItem().

jspGetLeftArg()

void jspGetLeftArg ( JsonPathItemv,
JsonPathItema 
)

Definition at line 1166 of file jsonpath.c.

1167{
1168 Assert(v->type == jpiAnd ||
1169 v->type == jpiOr ||
1170 v->type == jpiEqual ||
1171 v->type == jpiNotEqual ||
1172 v->type == jpiLess ||
1173 v->type == jpiGreater ||
1174 v->type == jpiLessOrEqual ||
1175 v->type == jpiGreaterOrEqual ||
1176 v->type == jpiAdd ||
1177 v->type == jpiSub ||
1178 v->type == jpiMul ||
1179 v->type == jpiDiv ||
1180 v->type == jpiMod ||
1181 v->type == jpiStartsWith ||
1182 v->type == jpiDecimal);
1183
1185}
struct JsonPathItem::@150::@151 args
int32 left
Definition: jsonpath.h:153

References a, JsonPathItem::args, Assert(), JsonPathItem::base, JsonPathItem::content, jpiAdd, jpiAnd, jpiDecimal, jpiDiv, jpiEqual, jpiGreater, jpiGreaterOrEqual, jpiLess, jpiLessOrEqual, jpiMod, jpiMul, jpiNotEqual, jpiOr, jpiStartsWith, jpiSub, jspInitByBuffer(), JsonPathItem::left, and JsonPathItem::type.

Referenced by executeBinaryArithmExpr(), executeBoolItem(), executeItemOptUnwrapTarget(), extract_jsp_bool_expr(), jspIsMutableWalker(), and printJsonPathItem().

jspGetNext()

bool jspGetNext ( JsonPathItemv,
JsonPathItema 
)

Definition at line 1099 of file jsonpath.c.

1100{
1101 if (jspHasNext(v))
1102 {
1103 Assert(v->type == jpiNull ||
1104 v->type == jpiString ||
1105 v->type == jpiNumeric ||
1106 v->type == jpiBool ||
1107 v->type == jpiAnd ||
1108 v->type == jpiOr ||
1109 v->type == jpiNot ||
1110 v->type == jpiIsUnknown ||
1111 v->type == jpiEqual ||
1112 v->type == jpiNotEqual ||
1113 v->type == jpiLess ||
1114 v->type == jpiGreater ||
1115 v->type == jpiLessOrEqual ||
1116 v->type == jpiGreaterOrEqual ||
1117 v->type == jpiAdd ||
1118 v->type == jpiSub ||
1119 v->type == jpiMul ||
1120 v->type == jpiDiv ||
1121 v->type == jpiMod ||
1122 v->type == jpiPlus ||
1123 v->type == jpiMinus ||
1124 v->type == jpiAnyArray ||
1125 v->type == jpiAnyKey ||
1126 v->type == jpiIndexArray ||
1127 v->type == jpiAny ||
1128 v->type == jpiKey ||
1129 v->type == jpiCurrent ||
1130 v->type == jpiRoot ||
1131 v->type == jpiVariable ||
1132 v->type == jpiFilter ||
1133 v->type == jpiExists ||
1134 v->type == jpiType ||
1135 v->type == jpiSize ||
1136 v->type == jpiAbs ||
1137 v->type == jpiFloor ||
1138 v->type == jpiCeiling ||
1139 v->type == jpiDouble ||
1140 v->type == jpiDatetime ||
1141 v->type == jpiKeyValue ||
1142 v->type == jpiLast ||
1143 v->type == jpiStartsWith ||
1144 v->type == jpiLikeRegex ||
1145 v->type == jpiBigint ||
1146 v->type == jpiBoolean ||
1147 v->type == jpiDate ||
1148 v->type == jpiDecimal ||
1149 v->type == jpiInteger ||
1150 v->type == jpiNumber ||
1151 v->type == jpiStringFunc ||
1152 v->type == jpiTime ||
1153 v->type == jpiTimeTz ||
1154 v->type == jpiTimestamp ||
1155 v->type == jpiTimestampTz);
1156
1157 if (a)
1158 jspInitByBuffer(a, v->base, v->nextPos);
1159 return true;
1160 }
1161
1162 return false;
1163}
#define jspHasNext(jsp)
Definition: jsonpath.h:194
int32 nextPos
Definition: jsonpath.h:140

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, jpiString, jpiStringFunc, jpiSub, jpiTime, jpiTimestamp, jpiTimestampTz, jpiTimeTz, jpiType, jpiVariable, jspHasNext, jspInitByBuffer(), JsonPathItem::nextPos, and JsonPathItem::type.

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

jspGetNumeric()

jspGetRightArg()

void jspGetRightArg ( JsonPathItemv,
JsonPathItema 
)

Definition at line 1188 of file jsonpath.c.

1189{
1190 Assert(v->type == jpiAnd ||
1191 v->type == jpiOr ||
1192 v->type == jpiEqual ||
1193 v->type == jpiNotEqual ||
1194 v->type == jpiLess ||
1195 v->type == jpiGreater ||
1196 v->type == jpiLessOrEqual ||
1197 v->type == jpiGreaterOrEqual ||
1198 v->type == jpiAdd ||
1199 v->type == jpiSub ||
1200 v->type == jpiMul ||
1201 v->type == jpiDiv ||
1202 v->type == jpiMod ||
1203 v->type == jpiStartsWith ||
1204 v->type == jpiDecimal);
1205
1207}
int32 right
Definition: jsonpath.h:154

References a, JsonPathItem::args, Assert(), JsonPathItem::base, JsonPathItem::content, jpiAdd, jpiAnd, jpiDecimal, jpiDiv, jpiEqual, jpiGreater, jpiGreaterOrEqual, jpiLess, jpiLessOrEqual, jpiMod, jpiMul, jpiNotEqual, jpiOr, jpiStartsWith, jpiSub, jspInitByBuffer(), JsonPathItem::right, and JsonPathItem::type.

Referenced by executeBinaryArithmExpr(), executeBoolItem(), executeItemOptUnwrapTarget(), extract_jsp_bool_expr(), jspIsMutableWalker(), and printJsonPathItem().

jspGetString()

char * jspGetString ( JsonPathItemv,
int32len 
)

jspInit()

void jspInit ( JsonPathItemv,
JsonPathjs 
)

Definition at line 980 of file jsonpath.c.

981{
983 jspInitByBuffer(v, js->data, 0);
984}
#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 ( JsonPathItemv,
char *  base,
int32  pos 
)

Definition at line 990 of file jsonpath.c.

991{
992 v->base = base + pos;
993
994 read_byte(v->type, base, pos);
995 pos = INTALIGN((uintptr_t) (base + pos)) - (uintptr_t) base;
996 read_int32(v->nextPos, base, pos);
997
998 switch (v->type)
999 {
1000 case jpiNull:
1001 case jpiRoot:
1002 case jpiCurrent:
1003 case jpiAnyArray:
1004 case jpiAnyKey:
1005 case jpiType:
1006 case jpiSize:
1007 case jpiAbs:
1008 case jpiFloor:
1009 case jpiCeiling:
1010 case jpiDouble:
1011 case jpiKeyValue:
1012 case jpiLast:
1013 case jpiBigint:
1014 case jpiBoolean:
1015 case jpiDate:
1016 case jpiInteger:
1017 case jpiNumber:
1018 case jpiStringFunc:
1019 break;
1020 case jpiString:
1021 case jpiKey:
1022 case jpiVariable:
1023 read_int32(v->content.value.datalen, base, pos);
1024 /* FALLTHROUGH */
1025 case jpiNumeric:
1026 case jpiBool:
1027 v->content.value.data = base + pos;
1028 break;
1029 case jpiAnd:
1030 case jpiOr:
1031 case jpiEqual:
1032 case jpiNotEqual:
1033 case jpiLess:
1034 case jpiGreater:
1035 case jpiLessOrEqual:
1036 case jpiGreaterOrEqual:
1037 case jpiAdd:
1038 case jpiSub:
1039 case jpiMul:
1040 case jpiDiv:
1041 case jpiMod:
1042 case jpiStartsWith:
1043 case jpiDecimal:
1044 read_int32(v->content.args.left, base, pos);
1045 read_int32(v->content.args.right, base, pos);
1046 break;
1047 case jpiNot:
1048 case jpiIsUnknown:
1049 case jpiExists:
1050 case jpiPlus:
1051 case jpiMinus:
1052 case jpiFilter:
1053 case jpiDatetime:
1054 case jpiTime:
1055 case jpiTimeTz:
1056 case jpiTimestamp:
1057 case jpiTimestampTz:
1058 read_int32(v->content.arg, base, pos);
1059 break;
1060 case jpiIndexArray:
1061 read_int32(v->content.array.nelems, base, pos);
1062 read_int32_n(v->content.array.elems, base, pos,
1063 v->content.array.nelems * 2);
1064 break;
1065 case jpiAny:
1066 read_int32(v->content.anybounds.first, base, pos);
1067 read_int32(v->content.anybounds.last, base, pos);
1068 break;
1069 case jpiLikeRegex:
1070 read_int32(v->content.like_regex.flags, base, pos);
1071 read_int32(v->content.like_regex.expr, base, pos);
1072 read_int32(v->content.like_regex.patternlen, base, pos);
1073 v->content.like_regex.pattern = base + pos;
1074 break;
1075 default:
1076 elog(ERROR, "unrecognized jsonpath item type: %d", v->type);
1077 }
1078}
#define INTALIGN(LEN)
Definition: c.h:807
#define read_byte(v, b, p)
Definition: jsonpath.c:961
#define read_int32_n(v, b, p, n)
Definition: jsonpath.c:971
#define read_int32(v, b, p)
Definition: jsonpath.c:966
uint32 first
Definition: jsonpath.h:174
int32 nelems
Definition: jsonpath.h:163
struct JsonPathItem::@150::@155 like_regex
uint32 flags
Definition: jsonpath.h:189
uint32 last
Definition: jsonpath.h:175
struct JsonPathItem::@150::@153 anybounds
int32 patternlen
Definition: jsonpath.h:188
char * pattern
Definition: jsonpath.h:187
int32 expr
Definition: jsonpath.h:186

References JsonPathItem::anybounds, JsonPathItem::arg, JsonPathItem::args, JsonPathItem::array, JsonPathItem::base, JsonPathItem::content, JsonPathItem::data, JsonPathItem::datalen, JsonPathItem::elems, elog, ERROR, JsonPathItem::expr, 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, jpiString, jpiStringFunc, jpiSub, jpiTime, jpiTimestamp, jpiTimestampTz, jpiTimeTz, jpiType, jpiVariable, JsonPathItem::last, JsonPathItem::left, JsonPathItem::like_regex, JsonPathItem::nelems, JsonPathItem::nextPos, JsonPathItem::pattern, JsonPathItem::patternlen, 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 ( JsonPathpath,
Listvarnames,
Listvarexprs 
)

Definition at line 1280 of file jsonpath.c.

1281{
1282 struct JsonPathMutableContext cxt;
1283 JsonPathItem jpi;
1284
1285 cxt.varnames = varnames;
1286 cxt.varexprs = varexprs;
1287 cxt.current = jpdsNonDateTime;
1288 cxt.lax = (path->header & JSONPATH_LAX) != 0;
1289 cxt.mutable = false;
1290
1291 jspInit(&jpi, path);
1292 (void) jspIsMutableWalker(&jpi, &cxt);
1293
1294 return cxt.mutable;
1295}
static enum JsonPathDatatypeStatus jspIsMutableWalker(JsonPathItem *jpi, struct JsonPathMutableContext *cxt)
Definition: jsonpath.c:1301
void jspInit(JsonPathItem *v, JsonPath *js)
Definition: jsonpath.c:980
@ jpdsNonDateTime
Definition: jsonpath.c:1256

References JsonPathMutableContext::current, 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 )

Definition at line 843 of file jsonpath.c.

844{
845 switch (type)
846 {
847 case jpiAnd:
848 return "&&";
849 case jpiOr:
850 return "||";
851 case jpiEqual:
852 return "==";
853 case jpiNotEqual:
854 return "!=";
855 case jpiLess:
856 return "<";
857 case jpiGreater:
858 return ">";
859 case jpiLessOrEqual:
860 return "<=";
862 return ">=";
863 case jpiAdd:
864 case jpiPlus:
865 return "+";
866 case jpiSub:
867 case jpiMinus:
868 return "-";
869 case jpiMul:
870 return "*";
871 case jpiDiv:
872 return "/";
873 case jpiMod:
874 return "%";
875 case jpiType:
876 return "type";
877 case jpiSize:
878 return "size";
879 case jpiAbs:
880 return "abs";
881 case jpiFloor:
882 return "floor";
883 case jpiCeiling:
884 return "ceiling";
885 case jpiDouble:
886 return "double";
887 case jpiDatetime:
888 return "datetime";
889 case jpiKeyValue:
890 return "keyvalue";
891 case jpiStartsWith:
892 return "starts with";
893 case jpiLikeRegex:
894 return "like_regex";
895 case jpiBigint:
896 return "bigint";
897 case jpiBoolean:
898 return "boolean";
899 case jpiDate:
900 return "date";
901 case jpiDecimal:
902 return "decimal";
903 case jpiInteger:
904 return "integer";
905 case jpiNumber:
906 return "number";
907 case jpiStringFunc:
908 return "string";
909 case jpiTime:
910 return "time";
911 case jpiTimeTz:
912 return "time_tz";
913 case jpiTimestamp:
914 return "timestamp";
915 case jpiTimestampTz:
916 return "timestamp_tz";
917 default:
918 elog(ERROR, "unrecognized jsonpath item type: %d", type);
919 return NULL;
920 }
921}
const char * type

References elog, ERROR, 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, jpiStringFunc, jpiSub, jpiTime, jpiTimestamp, jpiTimestampTz, jpiTimeTz, jpiType, and type.

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

parsejsonpath()

JsonPathParseResult * parsejsonpath ( const char *  str,
int  len,
struct Nodeescontext 
)

Definition at line 528 of file jsonpath_scan.l.

529{
531 yyscan_t scanner;
532 struct jsonpath_yy_extra_type yyext;
533
534 if (jsonpath_yylex_init(&scanner) != 0)
535 elog(ERROR, "yylex_init() failed: %m");
536
537 yyset_extra(&yyext, scanner);
538
539 if (len <= 0)
540 len = strlen(str);
541
542 jsonpath_yy_scan_bytes(str, len, scanner);
543
544 if (jsonpath_yyparse(&parseresult, escontext, scanner) != 0)
545 jsonpath_yyerror(NULL, escontext, scanner, "invalid input"); /* shouldn't happen */
546
547 jsonpath_yylex_destroy(scanner);
548
549 return parseresult;
550}
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)
Definition: jsonpath_scan.l:362

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

Referenced by jsonPathFromCstring().

Variable Documentation

JsonbTableRoutine

PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine
extern

Definition at line 371 of file jsonpath_exec.c.

Referenced by ExecInitTableFuncScan().

AltStyle によって変換されたページ (->オリジナル) /