PostgreSQL Source Code  git master
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
}
 

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)
 

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 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 209 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

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 path,
bool error,
List vars 
)

Definition at line 3878 of file jsonpath_exec.c.

3879 {
3881 
3882  res = executeJsonPath(jp, vars,
3884  DatumGetJsonbP(jb), !error, NULL, true);
3885 
3886  Assert(error || !jperIsError(res));
3887 
3888  if (error && jperIsError(res))
3889  *error = true;
3890 
3891  return res == jperOk;
3892 }
#define Assert(condition)
Definition: c.h:858
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)
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 3901 of file jsonpath_exec.c.

3903 {
3904  JsonbValue *singleton;
3905  bool wrap;
3906  JsonValueList found = {0};
3908  int count;
3909 
3910  res = executeJsonPath(jp, vars,
3912  DatumGetJsonbP(jb), !error, &found, true);
3913  Assert(error || !jperIsError(res));
3914  if (error && jperIsError(res))
3915  {
3916  *error = true;
3917  *empty = false;
3918  return (Datum) 0;
3919  }
3920 
3921  /* WRAP or not? */
3922  count = JsonValueListLength(&found);
3923  singleton = count > 0 ? JsonValueListHead(&found) : NULL;
3924  if (singleton == NULL)
3925  wrap = false;
3926  else if (wrapper == JSW_NONE || wrapper == JSW_UNSPEC)
3927  wrap = false;
3928  else if (wrapper == JSW_UNCONDITIONAL)
3929  wrap = true;
3930  else if (wrapper == JSW_CONDITIONAL)
3931  wrap = count > 1 ||
3932  IsAJsonbScalar(singleton) ||
3933  (singleton->type == jbvBinary &&
3934  JsonContainerIsScalar(singleton->val.binary.data));
3935  else
3936  {
3937  elog(ERROR, "unrecognized json wrapper %d", wrapper);
3938  wrap = false;
3939  }
3940 
3941  if (wrap)
3943 
3944  /* No wrapping means only one item is expected. */
3945  if (count > 1)
3946  {
3947  if (error)
3948  {
3949  *error = true;
3950  return (Datum) 0;
3951  }
3952 
3953  ereport(ERROR,
3954  (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
3955  errmsg("JSON path expression in JSON_QUERY should return singleton item without wrapper"),
3956  errhint("Use WITH WRAPPER clause to wrap SQL/JSON item sequence into array.")));
3957  }
3958 
3959  if (singleton)
3960  return JsonbPGetDatum(JsonbValueToJsonb(singleton));
3961 
3962  *empty = true;
3963  return PointerGetDatum(NULL);
3964 }
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:1719
@ JSW_CONDITIONAL
Definition: primnodes.h:1718
@ JSW_UNSPEC
Definition: primnodes.h:1716
@ JSW_NONE
Definition: primnodes.h:1717
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 3973 of file jsonpath_exec.c.

3974 {
3975  JsonbValue *res;
3976  JsonValueList found = {0};
3978  int count;
3979 
3981  DatumGetJsonbP(jb),
3982  !error, &found, true);
3983 
3984  Assert(error || !jperIsError(jper));
3985 
3986  if (error && jperIsError(jper))
3987  {
3988  *error = true;
3989  *empty = false;
3990  return NULL;
3991  }
3992 
3993  count = JsonValueListLength(&found);
3994 
3995  *empty = (count == 0);
3996 
3997  if (*empty)
3998  return NULL;
3999 
4000  /* JSON_VALUE expects to get only singletons. */
4001  if (count > 1)
4002  {
4003  if (error)
4004  {
4005  *error = true;
4006  return NULL;
4007  }
4008 
4009  ereport(ERROR,
4010  (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
4011  errmsg("JSON path expression in JSON_VALUE should return singleton scalar item")));
4012  }
4013 
4014  res = JsonValueListHead(&found);
4015  if (res->type == jbvBinary && JsonContainerIsScalar(res->val.binary.data))
4016  JsonbExtractScalar(res->val.binary.data, res);
4017 
4018  /* JSON_VALUE expects to get only scalars. */
4019  if (!IsAJsonbScalar(res))
4020  {
4021  if (error)
4022  {
4023  *error = true;
4024  return NULL;
4025  }
4026 
4027  ereport(ERROR,
4028  (errcode(ERRCODE_SQL_JSON_SCALAR_REQUIRED),
4029  errmsg("JSON path expression in JSON_VALUE should return singleton scalar item")));
4030  }
4031 
4032  if (res->type == jbvNull)
4033  return NULL;
4034 
4035  return res;
4036 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:182
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
union JsonPathItem::@137 content
char * base
Definition: jsonpath.h:146
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(), 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::@137::@139 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::@137::@141 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::@137::@138 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: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(), 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: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 
)

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:808
#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::@137::@142 like_regex
struct JsonPathItem::@137::@140 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().

Variable Documentation

◆ JsonbTableRoutine

PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine
extern

Definition at line 372 of file jsonpath_exec.c.

Referenced by ExecInitTableFuncScan().