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

◆ JsonPathParseResult

◆ JsonPathVariable

Enumeration Type Documentation

◆ JsonPathItemType

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

Definition at line 62 of file jsonpath.h.

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

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

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

Referenced by ExecEvalJsonExprPath().

◆ JsonPathQuery()

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

Definition at line 3914 of file jsonpath_exec.c.

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

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

Referenced by ExecEvalJsonExprPath().

◆ JsonPathValue()

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

Definition at line 4008 of file jsonpath_exec.c.

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

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

Referenced by ExecEvalJsonExprPath().

◆ jspConvertRegexFlags()

bool jspConvertRegexFlags ( uint32  xflags,
int *  result,
struct 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:73
void jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
Definition: jsonpath.c:990
union JsonPathItem::@152 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(), jspIsMutableWalker(), 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:77
struct JsonPathItem::@152::@154::@158 * elems
struct JsonPathItem::@152::@154 array

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

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

◆ jspGetBool()

bool jspGetBool ( JsonPathItem v)

Definition at line 1210 of file jsonpath.c.

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

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

Referenced by getJsonPathItem(), and printJsonPathItem().

◆ jspGetLeftArg()

void jspGetLeftArg ( JsonPathItem v,
JsonPathItem a 
)

Definition at line 1166 of file jsonpath.c.

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

Referenced by executeBinaryArithmExpr(), executeBoolItem(), executeItemOptUnwrapTarget(), extract_jsp_bool_expr(), jspIsMutableWalker(), 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(), jspIsMutableWalker(), and printJsonPathItem().

◆ jspGetNumeric()

◆ jspGetRightArg()

void jspGetRightArg ( JsonPathItem v,
JsonPathItem a 
)

◆ jspGetString()

◆ 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:821
#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::@152::@155 anybounds
uint32 first
Definition: jsonpath.h:174
int32 nelems
Definition: jsonpath.h:163
uint32 flags
Definition: jsonpath.h:189
struct JsonPathItem::@152::@157 like_regex
uint32 last
Definition: jsonpath.h:175
int32 patternlen
Definition: jsonpath.h:188
char * pattern
Definition: jsonpath.h:187
int32 expr
Definition: jsonpath.h:186

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

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

◆ jspIsMutable()

bool jspIsMutable ( 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 "<=";
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 
)

Definition at line 528 of file jsonpath_scan.l.

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

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

Referenced by jsonPathFromCstring().

Variable Documentation

◆ JsonbTableRoutine

PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine
extern

Definition at line 371 of file jsonpath_exec.c.

Referenced by ExecInitTableFuncScan().