PostgreSQL Source Code  git master
jsonpath.h File Reference
#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
}
 

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)
 
char * jspGetString (JsonPathItem *v, int32 *len)
 
bool jspGetArraySubscript (JsonPathItem *v, JsonPathItem *from, JsonPathItem *to, int i)
 
bool jspIsMutable (JsonPath *path, List *varnames, List *varexprs)
 
const char * jspOperationName (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 *path, bool *error, List *vars)
 
Datum JsonPathQuery (Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, bool *error, List *vars)
 
JsonbValueJsonPathValue (Datum jb, JsonPath *jp, bool *empty, bool *error, List *vars)
 

Macro Definition Documentation

◆ JSONPATH_HDRSZ

#define JSONPATH_HDRSZ   (offsetof(JsonPath, data))

Definition at line 31 of file jsonpath.h.

◆ JSONPATH_LAX

#define JSONPATH_LAX   (0x80000000)

Definition at line 30 of file jsonpath.h.

◆ JSONPATH_VERSION

#define JSONPATH_VERSION   (0x01)

Definition at line 29 of file jsonpath.h.

◆ JSP_REGEX_DOTALL

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

Definition at line 121 of file jsonpath.h.

◆ JSP_REGEX_ICASE

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

Definition at line 120 of file jsonpath.h.

◆ JSP_REGEX_MLINE

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

Definition at line 122 of file jsonpath.h.

◆ JSP_REGEX_QUOTE

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

Definition at line 124 of file jsonpath.h.

◆ JSP_REGEX_WSPACE

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

Definition at line 123 of file jsonpath.h.

◆ jspHasNext

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

Definition at line 193 of file jsonpath.h.

◆ jspIsScalar

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

Definition at line 49 of file jsonpath.h.

◆ PG_GETARG_JSONPATH_P

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

Definition at line 45 of file jsonpath.h.

◆ PG_GETARG_JSONPATH_P_COPY

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

Definition at line 46 of file jsonpath.h.

◆ PG_RETURN_JSONPATH_P

#define PG_RETURN_JSONPATH_P (   p)    PG_RETURN_POINTER(p)

Definition at line 47 of file jsonpath.h.

Typedef Documentation

◆ JsonPathItem

typedef struct JsonPathItem JsonPathItem

◆ JsonPathItemType

◆ JsonPathParseItem

Definition at line 208 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 61 of file jsonpath.h.

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

Function Documentation

◆ DatumGetJsonPathP()

static JsonPath* DatumGetJsonPathP ( Datum  d)
inlinestatic

Definition at line 34 of file jsonpath.h.

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

References PG_DETOAST_DATUM.

Referenced by contain_mutable_functions_walker(), and ExecEvalJsonExprPath().

◆ DatumGetJsonPathPCopy()

static JsonPath* DatumGetJsonPathPCopy ( Datum  d)
inlinestatic

Definition at line 40 of file jsonpath.h.

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

References PG_DETOAST_DATUM_COPY.

◆ JsonPathExists()

bool JsonPathExists ( Datum  jb,
JsonPath path,
bool error,
List vars 
)

Definition at line 3762 of file jsonpath_exec.c.

3763 {
3765 
3766  res = executeJsonPath(jp, vars,
3768  DatumGetJsonbP(jb), !error, NULL, true);
3769 
3770  Assert(error || !jperIsError(res));
3771 
3772  if (error && jperIsError(res))
3773  *error = true;
3774 
3775  return res == jperOk;
3776 }
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)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
static void error(void)
Definition: sql-dyntest.c:147
Definition: regcomp.c:281

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

Referenced by ExecEvalJsonExprPath().

◆ JsonPathQuery()

Datum JsonPathQuery ( Datum  jb,
JsonPath jp,
JsonWrapper  wrapper,
bool empty,
bool error,
List vars 
)

Definition at line 3785 of file jsonpath_exec.c.

3787 {
3788  JsonbValue *singleton;
3789  bool wrap;
3790  JsonValueList found = {0};
3792  int count;
3793 
3794  res = executeJsonPath(jp, vars,
3796  DatumGetJsonbP(jb), !error, &found, true);
3797  Assert(error || !jperIsError(res));
3798  if (error && jperIsError(res))
3799  {
3800  *error = true;
3801  *empty = false;
3802  return (Datum) 0;
3803  }
3804 
3805  /* WRAP or not? */
3806  count = JsonValueListLength(&found);
3807  singleton = count > 0 ? JsonValueListHead(&found) : NULL;
3808  if (singleton == NULL)
3809  wrap = false;
3810  else if (wrapper == JSW_NONE || wrapper == JSW_UNSPEC)
3811  wrap = false;
3812  else if (wrapper == JSW_UNCONDITIONAL)
3813  wrap = true;
3814  else if (wrapper == JSW_CONDITIONAL)
3815  wrap = count > 1 ||
3816  IsAJsonbScalar(singleton) ||
3817  (singleton->type == jbvBinary &&
3818  JsonContainerIsScalar(singleton->val.binary.data));
3819  else
3820  {
3821  elog(ERROR, "unrecognized json wrapper %d", wrapper);
3822  wrap = false;
3823  }
3824 
3825  if (wrap)
3827 
3828  /* No wrapping means only one item is expected. */
3829  if (count > 1)
3830  {
3831  if (error)
3832  {
3833  *error = true;
3834  return (Datum) 0;
3835  }
3836 
3837  ereport(ERROR,
3838  (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
3839  errmsg("JSON path expression in JSON_QUERY should return singleton item without wrapper"),
3840  errhint("Use WITH WRAPPER clause to wrap SQL/JSON item sequence into array.")));
3841  }
3842 
3843  if (singleton)
3844  return JsonbPGetDatum(JsonbValueToJsonb(singleton));
3845 
3846  *empty = true;
3847  return PointerGetDatum(NULL);
3848 }
int errhint(const char *fmt,...)
Definition: elog.c:1319
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
@ jbvBinary
Definition: jsonb.h:236
#define JsonContainerIsScalar(jc)
Definition: jsonb.h:207
static Datum JsonbPGetDatum(const Jsonb *p)
Definition: jsonb.h:386
#define IsAJsonbScalar(jsonbval)
Definition: jsonb.h:297
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:322
uintptr_t Datum
Definition: postgres.h:64
@ JSW_UNCONDITIONAL
Definition: primnodes.h:1705
@ JSW_CONDITIONAL
Definition: primnodes.h:1704
@ JSW_UNSPEC
Definition: primnodes.h:1702
@ JSW_NONE
Definition: primnodes.h:1703
enum jbvType type
Definition: jsonb.h:255
char * val
Definition: jsonb.h:264

References Assert(), CountJsonPathVars(), DatumGetJsonbP(), elog, ereport, errcode(), errhint(), errmsg(), ERROR, error(), executeJsonPath(), GetJsonPathVar(), IsAJsonbScalar, jbvBinary, jperIsError, JsonbPGetDatum(), JsonbValueToJsonb(), JsonContainerIsScalar, JsonValueListHead(), JsonValueListLength(), JSW_CONDITIONAL, JSW_NONE, JSW_UNCONDITIONAL, JSW_UNSPEC, PointerGetDatum(), res, JsonbValue::type, JsonbValue::val, and wrapItemsInArray().

Referenced by ExecEvalJsonExprPath().

◆ JsonPathValue()

JsonbValue* JsonPathValue ( Datum  jb,
JsonPath jp,
bool empty,
bool error,
List vars 
)

Definition at line 3857 of file jsonpath_exec.c.

3858 {
3859  JsonbValue *res;
3860  JsonValueList found = {0};
3862  int count;
3863 
3865  DatumGetJsonbP(jb),
3866  !error, &found, true);
3867 
3868  Assert(error || !jperIsError(jper));
3869 
3870  if (error && jperIsError(jper))
3871  {
3872  *error = true;
3873  *empty = false;
3874  return NULL;
3875  }
3876 
3877  count = JsonValueListLength(&found);
3878 
3879  *empty = (count == 0);
3880 
3881  if (*empty)
3882  return NULL;
3883 
3884  /* JSON_VALUE expects to get only singletons. */
3885  if (count > 1)
3886  {
3887  if (error)
3888  {
3889  *error = true;
3890  return NULL;
3891  }
3892 
3893  ereport(ERROR,
3894  (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
3895  errmsg("JSON path expression in JSON_VALUE should return singleton scalar item")));
3896  }
3897 
3898  res = JsonValueListHead(&found);
3899  if (res->type == jbvBinary && JsonContainerIsScalar(res->val.binary.data))
3900  JsonbExtractScalar(res->val.binary.data, res);
3901 
3902  /* JSON_VALUE expects to get only scalars. */
3903  if (!IsAJsonbScalar(res))
3904  {
3905  if (error)
3906  {
3907  *error = true;
3908  return NULL;
3909  }
3910 
3911  ereport(ERROR,
3912  (errcode(ERRCODE_SQL_JSON_SCALAR_REQUIRED),
3913  errmsg("JSON path expression in JSON_VALUE should return singleton scalar item")));
3914  }
3915 
3916  if (res->type == jbvNull)
3917  return NULL;
3918 
3919  return res;
3920 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:169
bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)
Definition: jsonb.c:1968
int binary
Definition: libpq-int.h:182

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

Referenced by ExecEvalJsonExprPath().

◆ jspConvertRegexFlags()

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

Referenced by executeLikeRegex().

◆ jspGetArg()

void jspGetArg ( JsonPathItem v,
JsonPathItem a 
)

Definition at line 1074 of file jsonpath.c.

1075 {
1076  Assert(v->type == jpiNot ||
1077  v->type == jpiIsUnknown ||
1078  v->type == jpiPlus ||
1079  v->type == jpiMinus ||
1080  v->type == jpiFilter ||
1081  v->type == jpiExists ||
1082  v->type == jpiDatetime ||
1083  v->type == jpiTime ||
1084  v->type == jpiTimeTz ||
1085  v->type == jpiTimestamp ||
1086  v->type == jpiTimestampTz);
1087 
1088  jspInitByBuffer(a, v->base, v->content.arg);
1089 }
int a
Definition: isn.c:69
void jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
Definition: jsonpath.c:983
char * base
Definition: jsonpath.h:145
int32 arg
Definition: jsonpath.h:157
JsonPathItemType type
Definition: jsonpath.h:136
union JsonPathItem::@136 content

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(), and printJsonPathItem().

◆ jspGetArraySubscript()

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

Definition at line 1231 of file jsonpath.c.

1233 {
1234  Assert(v->type == jpiIndexArray);
1235 
1236  jspInitByBuffer(from, v->base, v->content.array.elems[i].from);
1237 
1238  if (!v->content.array.elems[i].to)
1239  return false;
1240 
1241  jspInitByBuffer(to, v->base, v->content.array.elems[i].to);
1242 
1243  return true;
1244 }
int i
Definition: isn.c:73
struct JsonPathItem::@136::@138 array

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

Referenced by executeItemOptUnwrapTarget(), and printJsonPathItem().

◆ jspGetBool()

bool jspGetBool ( JsonPathItem v)

Definition at line 1203 of file jsonpath.c.

1204 {
1205  Assert(v->type == jpiBool);
1206 
1207  return (bool) *v->content.value.data;
1208 }
struct JsonPathItem::@136::@140 value

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

Referenced by getJsonPathItem(), and printJsonPathItem().

◆ jspGetLeftArg()

void jspGetLeftArg ( JsonPathItem v,
JsonPathItem a 
)

Definition at line 1159 of file jsonpath.c.

1160 {
1161  Assert(v->type == jpiAnd ||
1162  v->type == jpiOr ||
1163  v->type == jpiEqual ||
1164  v->type == jpiNotEqual ||
1165  v->type == jpiLess ||
1166  v->type == jpiGreater ||
1167  v->type == jpiLessOrEqual ||
1168  v->type == jpiGreaterOrEqual ||
1169  v->type == jpiAdd ||
1170  v->type == jpiSub ||
1171  v->type == jpiMul ||
1172  v->type == jpiDiv ||
1173  v->type == jpiMod ||
1174  v->type == jpiStartsWith ||
1175  v->type == jpiDecimal);
1176 
1177  jspInitByBuffer(a, v->base, v->content.args.left);
1178 }
struct JsonPathItem::@136::@137 args

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(), and JsonPathItem::type.

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

◆ jspGetNext()

bool jspGetNext ( JsonPathItem v,
JsonPathItem a 
)

Definition at line 1092 of file jsonpath.c.

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

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(), and printJsonPathItem().

◆ jspGetNumeric()

Numeric jspGetNumeric ( JsonPathItem v)

Definition at line 1211 of file jsonpath.c.

1212 {
1213  Assert(v->type == jpiNumeric);
1214 
1215  return (Numeric) v->content.value.data;
1216 }

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

Referenced by executeDateTimeMethod(), executeItemOptUnwrapTarget(), getJsonPathItem(), and printJsonPathItem().

◆ jspGetRightArg()

void jspGetRightArg ( JsonPathItem v,
JsonPathItem a 
)

Definition at line 1181 of file jsonpath.c.

1182 {
1183  Assert(v->type == jpiAnd ||
1184  v->type == jpiOr ||
1185  v->type == jpiEqual ||
1186  v->type == jpiNotEqual ||
1187  v->type == jpiLess ||
1188  v->type == jpiGreater ||
1189  v->type == jpiLessOrEqual ||
1190  v->type == jpiGreaterOrEqual ||
1191  v->type == jpiAdd ||
1192  v->type == jpiSub ||
1193  v->type == jpiMul ||
1194  v->type == jpiDiv ||
1195  v->type == jpiMod ||
1196  v->type == jpiStartsWith ||
1197  v->type == jpiDecimal);
1198 
1199  jspInitByBuffer(a, v->base, v->content.args.right);
1200 }

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(), and JsonPathItem::type.

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

◆ jspGetString()

char* jspGetString ( JsonPathItem v,
int32 len 
)

Definition at line 1219 of file jsonpath.c.

1220 {
1221  Assert(v->type == jpiKey ||
1222  v->type == jpiString ||
1223  v->type == jpiVariable);
1224 
1225  if (len)
1226  *len = v->content.value.datalen;
1227  return v->content.value.data;
1228 }
const void size_t len

References Assert(), JsonPathItem::content, jpiKey, jpiString, jpiVariable, len, JsonPathItem::type, and JsonPathItem::value.

Referenced by executeDateTimeMethod(), executeItemOptUnwrapTarget(), getJsonPathItem(), getJsonPathVariable(), jsonb_ops__add_path_item(), jsonb_path_ops__add_path_item(), and printJsonPathItem().

◆ jspInit()

void jspInit ( JsonPathItem v,
JsonPath js 
)

Definition at line 973 of file jsonpath.c.

974 {
976  jspInitByBuffer(v, js->data, 0);
977 }
#define JSONPATH_VERSION
Definition: jsonpath.h:29
#define JSONPATH_LAX
Definition: jsonpath.h:30
char data[FLEXIBLE_ARRAY_MEMBER]
Definition: jsonpath.h:26
uint32 header
Definition: jsonpath.h:25

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 
)

Definition at line 983 of file jsonpath.c.

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

References JsonPathItem::anybounds, JsonPathItem::arg, JsonPathItem::args, JsonPathItem::array, JsonPathItem::base, JsonPathItem::content, elog, ERROR, 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::like_regex, JsonPathItem::nextPos, read_byte, read_int32, read_int32_n, JsonPathItem::type, and JsonPathItem::value.

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

◆ jspIsMutable()

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

Definition at line 1273 of file jsonpath.c.

1274 {
1275  struct JsonPathMutableContext cxt;
1276  JsonPathItem jpi;
1277 
1278  cxt.varnames = varnames;
1279  cxt.varexprs = varexprs;
1280  cxt.current = jpdsNonDateTime;
1281  cxt.lax = (path->header & JSONPATH_LAX) != 0;
1282  cxt.mutable = false;
1283 
1284  jspInit(&jpi, path);
1285  (void) jspIsMutableWalker(&jpi, &cxt);
1286 
1287  return cxt.mutable;
1288 }
static enum JsonPathDatatypeStatus jspIsMutableWalker(JsonPathItem *jpi, struct JsonPathMutableContext *cxt)
Definition: jsonpath.c:1294
void jspInit(JsonPathItem *v, JsonPath *js)
Definition: jsonpath.c:973
@ jpdsNonDateTime
Definition: jsonpath.c:1249

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 836 of file jsonpath.c.

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

Referenced by jsonPathFromCstring().