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 *jp, bool *error, List *vars)
 
Datum JsonPathQuery (Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, bool *error, List *vars, const char *column_name)
 
JsonbValueJsonPathValue (Datum jb, JsonPath *jp, bool *empty, bool *error, List *vars, const char *column_name)
 

Variables

PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine
 

Macro Definition Documentation

◆ JSONPATH_HDRSZ

#define JSONPATH_HDRSZ   (offsetof(JsonPath, data))

Definition at line 32 of file jsonpath.h.

◆ JSONPATH_LAX

#define JSONPATH_LAX   (0x80000000)

Definition at line 31 of file jsonpath.h.

◆ JSONPATH_VERSION

#define JSONPATH_VERSION   (0x01)

Definition at line 30 of file jsonpath.h.

◆ JSP_REGEX_DOTALL

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

Definition at line 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 jp,
bool error,
List vars 
)

Definition at line 3888 of file jsonpath_exec.c.

3889 {
3891 
3892  res = executeJsonPath(jp, vars,
3894  DatumGetJsonbP(jb), !error, NULL, true);
3895 
3896  Assert(error || !jperIsError(res));
3897 
3898  if (error && jperIsError(res))
3899  *error = true;
3900 
3901  return res == jperOk;
3902 }
#define Assert(condition)
Definition: c.h:849
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,
const char *  column_name 
)

Definition at line 3911 of file jsonpath_exec.c.

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

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

Referenced by ExecEvalJsonExprPath().

◆ JsonPathValue()

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

Definition at line 4005 of file jsonpath_exec.c.

4007 {
4008  JsonbValue *res;
4009  JsonValueList found = {0};
4011  int count;
4012 
4014  DatumGetJsonbP(jb),
4015  !error, &found, true);
4016 
4017  Assert(error || !jperIsError(jper));
4018 
4019  if (error && jperIsError(jper))
4020  {
4021  *error = true;
4022  *empty = false;
4023  return NULL;
4024  }
4025 
4026  count = JsonValueListLength(&found);
4027 
4028  *empty = (count == 0);
4029 
4030  if (*empty)
4031  return NULL;
4032 
4033  /* JSON_VALUE expects to get only singletons. */
4034  if (count > 1)
4035  {
4036  if (error)
4037  {
4038  *error = true;
4039  return NULL;
4040  }
4041 
4042  if (column_name)
4043  ereport(ERROR,
4044  (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
4045  errmsg("JSON path expression for column \"%s\" should return single scalar item",
4046  column_name)));
4047  else
4048  ereport(ERROR,
4049  (errcode(ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM),
4050  errmsg("JSON path expression in JSON_VALUE should return single scalar item")));
4051  }
4052 
4053  res = JsonValueListHead(&found);
4054  if (res->type == jbvBinary && JsonContainerIsScalar(res->val.binary.data))
4055  JsonbExtractScalar(res->val.binary.data, res);
4056 
4057  /* JSON_VALUE expects to get only scalars. */
4058  if (!IsAJsonbScalar(res))
4059  {
4060  if (error)
4061  {
4062  *error = true;
4063  return NULL;
4064  }
4065 
4066  if (column_name)
4067  ereport(ERROR,
4068  (errcode(ERRCODE_SQL_JSON_SCALAR_REQUIRED),
4069  errmsg("JSON path expression for column \"%s\" should return single scalar item",
4070  column_name)));
4071  else
4072  ereport(ERROR,
4073  (errcode(ERRCODE_SQL_JSON_SCALAR_REQUIRED),
4074  errmsg("JSON path expression in JSON_VALUE should return single scalar item")));
4075  }
4076 
4077  if (res->type == jbvNull)
4078  return NULL;
4079 
4080  return res;
4081 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:185
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
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 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 }
int a
Definition: isn.c:69
void jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
Definition: jsonpath.c:990
union JsonPathItem::@139 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 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 }
int i
Definition: isn.c:73
struct JsonPathItem::@139::@141 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 1210 of file jsonpath.c.

1211 {
1212  Assert(v->type == jpiBool);
1213 
1214  return (bool) *v->content.value.data;
1215 }
struct JsonPathItem::@139::@143 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 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 
1184  jspInitByBuffer(a, v->base, v->content.args.left);
1185 }
struct JsonPathItem::@139::@140 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 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(), and printJsonPathItem().

◆ jspGetNumeric()

Numeric jspGetNumeric ( JsonPathItem v)

Definition at line 1218 of file jsonpath.c.

1219 {
1220  Assert(v->type == jpiNumeric);
1221 
1222  return (Numeric) v->content.value.data;
1223 }

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 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 
1206  jspInitByBuffer(a, v->base, v->content.args.right);
1207 }

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

1227 {
1228  Assert(v->type == jpiKey ||
1229  v->type == jpiString ||
1230  v->type == jpiVariable);
1231 
1232  if (len)
1233  *len = v->content.value.datalen;
1234  return v->content.value.data;
1235 }
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 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 ( JsonPathItem v,
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:799
#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
struct JsonPathItem::@139::@144 like_regex
struct JsonPathItem::@139::@142 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 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 "<=";
861  case jpiGreaterOrEqual:
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 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().