1/*-------------------------------------------------------------------------
4 * Definitions for jsonpath datatype
6 * Copyright (c) 2019-2025, PostgreSQL Global Development Group
9 * src/include/utils/jsonpath.h
11 *-------------------------------------------------------------------------
30 #define JSONPATH_VERSION (0x01)
31 #define JSONPATH_LAX (0x80000000)
32 #define JSONPATH_HDRSZ (offsetof(JsonPath, data))
46 #define PG_GETARG_JSONPATH_P(x) DatumGetJsonPathP(PG_GETARG_DATUM(x))
47 #define PG_GETARG_JSONPATH_P_COPY(x) DatumGetJsonPathPCopy(PG_GETARG_DATUM(x))
48 #define PG_RETURN_JSONPATH_P(p) PG_RETURN_POINTER(p)
50 #define jspIsScalar(type) ((type) >= jpiNull && (type) <= jpiBool)
53 * All node's type of jsonpath expression
55 * These become part of the on-disk representation of the jsonpath type.
56 * Therefore, to preserve pg_upgradability, the order must not be changed, and
57 * new values must be added at the end.
59 * It is recommended that switch cases etc. in other parts of the code also
60 * use this order, to maintain some consistency.
69 jpiOr,
/* predicate || predicate */
120/* XQuery regex mode flags for LIKE_REGEX predicate */
121 #define JSP_REGEX_ICASE 0x01 /* i flag, case insensitive */
122 #define JSP_REGEX_DOTALL 0x02 /* s flag, dot matches newline */
123 #define JSP_REGEX_MLINE 0x04 /* m flag, ^/$ match at newlines */
124 #define JSP_REGEX_WSPACE 0x08 /* x flag, ignore whitespace in pattern */
125 #define JSP_REGEX_QUOTE 0x10 /* q flag, no special characters */
128 * Support functions to parse/construct binary value.
129 * Unlike many other representation of expression the first/main
130 * node is not an operation but left operand of expression. That
131 * allows to implement cheap follow-path descending in jsonb
132 * structure and then execute operator with right operand
139 /* position form base to next node */
143 * pointer into JsonPath value to current node, all positions of current
144 * are relative to this base
150 /* classic operator with two operands: and, or etc */
157 /* any unary operation */
160 /* storage for jpiIndexArray: indexes of array */
180 char *
data;
/* for bool, numeric and string/key */
194 #define jspHasNext(jsp) ((jsp)->nextPos > 0)
212 * Parsing support data structures.
225 /* classic operator with two operands: and, or etc */
232 /* any unary operation */
235 /* storage for jpiIndexArray: indexes of array */
256 char *
pattern;
/* could not be not null-terminated */
267 char *
val;
/* could not be not null-terminated */
279 struct Node *escontext);
282 struct Node *escontext);
285 * Struct for details about external variables passed into jsonpath executor
290 int namelen;
/* strlen(name) as cache for GetJsonPathVar() */
298/* SQL/JSON query functions */
302 const char *column_name);
305 const char *column_name);
307/* For JSON_TABLE() */
#define FLEXIBLE_ARRAY_MEMBER
#define PG_DETOAST_DATUM_COPY(datum)
#define PG_DETOAST_DATUM(datum)
PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine
bool JsonPathExists(Datum jb, JsonPath *jp, bool *error, List *vars)
bool jspIsMutable(JsonPath *path, List *varnames, List *varexprs)
void jspGetLeftArg(JsonPathItem *v, JsonPathItem *a)
void jspGetArg(JsonPathItem *v, JsonPathItem *a)
void jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
bool jspGetBool(JsonPathItem *v)
void jspInit(JsonPathItem *v, JsonPath *js)
Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, bool *error, List *vars, const char *column_name)
char * jspGetString(JsonPathItem *v, int32 *len)
bool jspConvertRegexFlags(uint32 xflags, int *result, struct Node *escontext)
Numeric jspGetNumeric(JsonPathItem *v)
bool jspGetArraySubscript(JsonPathItem *v, JsonPathItem *from, JsonPathItem *to, int i)
struct JsonPathVariable JsonPathVariable
static JsonPath * DatumGetJsonPathPCopy(Datum d)
const char * jspOperationName(JsonPathItemType type)
bool jspGetNext(JsonPathItem *v, JsonPathItem *a)
JsonbValue * JsonPathValue(Datum jb, JsonPath *jp, bool *empty, bool *error, List *vars, const char *column_name)
JsonPathParseResult * parsejsonpath(const char *str, int len, struct Node *escontext)
struct JsonPathParseResult JsonPathParseResult
static JsonPath * DatumGetJsonPathP(Datum d)
void jspGetRightArg(JsonPathItem *v, JsonPathItem *a)
struct JsonPathItem JsonPathItem
struct JsonPathItem::@150::@151 args
struct JsonPathItem::@150::@155 like_regex
struct JsonPathItem::@150::@152::@156 * elems
union JsonPathItem::@150 content
struct JsonPathItem::@150::@152 array
struct JsonPathItem::@150::@154 value
struct JsonPathItem::@150::@153 anybounds
struct JsonPathParseItem::@157::@158 args
JsonPathParseItem * right
struct JsonPathParseItem::@157::@162 string
struct JsonPathParseItem::@157::@160 anybounds
struct JsonPathParseItem::@157::@159 array
struct JsonPathParseItem::@157::@161 like_regex
union JsonPathParseItem::@157 value
struct JsonPathParseItem::@157::@159::@163 * elems