| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifndef JSONPATH_H |
| | #define JSONPATH_H |
| |
|
| | #include "executor/tablefunc.h" |
| | #include "fmgr.h" |
| | #include "nodes/pg_list.h" |
| | #include "nodes/primnodes.h" |
| | #include "utils/jsonb.h" |
| |
|
| | typedef struct |
| | { |
| | int32 vl_len_; |
| | uint32 header; |
| | char data[FLEXIBLE_ARRAY_MEMBER]; |
| | } JsonPath; |
| |
|
| | #define JSONPATH_VERSION (0x01) |
| | #define JSONPATH_LAX (0x80000000) |
| | #define JSONPATH_HDRSZ (offsetof(JsonPath, data)) |
| |
|
| | static inline JsonPath * |
| | DatumGetJsonPathP(Datum d) |
| | { |
| | return (JsonPath *) PG_DETOAST_DATUM(d); |
| | } |
| |
|
| | static inline JsonPath * |
| | DatumGetJsonPathPCopy(Datum d) |
| | { |
| | return (JsonPath *) PG_DETOAST_DATUM_COPY(d); |
| | } |
| |
|
| | #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) |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | typedef 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, |
| | } JsonPathItemType; |
| |
|
| | |
| | #define JSP_REGEX_ICASE 0x01 |
| | #define JSP_REGEX_DOTALL 0x02 |
| | #define JSP_REGEX_MLINE 0x04 |
| | #define JSP_REGEX_WSPACE 0x08 |
| | #define JSP_REGEX_QUOTE 0x10 |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | typedef struct JsonPathItem |
| | { |
| | JsonPathItemType type; |
| |
|
| | |
| | int32 nextPos; |
| |
|
| | |
| | |
| | |
| | |
| | char *base; |
| |
|
| | union |
| | { |
| | |
| | struct |
| | { |
| | int32 left; |
| | int32 right; |
| | } args; |
| |
|
| | |
| | int32 arg; |
| |
|
| | |
| | struct |
| | { |
| | int32 nelems; |
| | struct |
| | { |
| | int32 from; |
| | int32 to; |
| | } *elems; |
| | } array; |
| |
|
| | |
| | struct |
| | { |
| | uint32 first; |
| | uint32 last; |
| | } anybounds; |
| |
|
| | struct |
| | { |
| | char *data; |
| | int32 datalen; |
| | } value; |
| |
|
| | struct |
| | { |
| | int32 expr; |
| | char *pattern; |
| | int32 patternlen; |
| | uint32 flags; |
| | } like_regex; |
| | } content; |
| | } JsonPathItem; |
| |
|
| | #define jspHasNext(jsp) ((jsp)->nextPos > 0) |
| |
|
| | extern void jspInit(JsonPathItem *v, JsonPath *js); |
| | extern void jspInitByBuffer(JsonPathItem *v, char *base, int32 pos); |
| | extern bool jspGetNext(JsonPathItem *v, JsonPathItem *a); |
| | extern void jspGetArg(JsonPathItem *v, JsonPathItem *a); |
| | extern void jspGetLeftArg(JsonPathItem *v, JsonPathItem *a); |
| | extern void jspGetRightArg(JsonPathItem *v, JsonPathItem *a); |
| | extern Numeric jspGetNumeric(JsonPathItem *v); |
| | extern bool jspGetBool(JsonPathItem *v); |
| | extern char *jspGetString(JsonPathItem *v, int32 *len); |
| | extern bool jspGetArraySubscript(JsonPathItem *v, JsonPathItem *from, |
| | JsonPathItem *to, int i); |
| | extern bool jspIsMutable(JsonPath *path, List *varnames, List *varexprs); |
| |
|
| | extern const char *jspOperationName(JsonPathItemType type); |
| |
|
| | |
| | |
| | |
| |
|
| | typedef struct JsonPathParseItem JsonPathParseItem; |
| |
|
| | struct JsonPathParseItem |
| | { |
| | JsonPathItemType type; |
| | JsonPathParseItem *next; |
| |
|
| | union |
| | { |
| |
|
| | |
| | struct |
| | { |
| | JsonPathParseItem *left; |
| | JsonPathParseItem *right; |
| | } args; |
| |
|
| | |
| | JsonPathParseItem *arg; |
| |
|
| | |
| | struct |
| | { |
| | int nelems; |
| | struct |
| | { |
| | JsonPathParseItem *from; |
| | JsonPathParseItem *to; |
| | } *elems; |
| | } array; |
| |
|
| | |
| | struct |
| | { |
| | uint32 first; |
| | uint32 last; |
| | } anybounds; |
| |
|
| | struct |
| | { |
| | JsonPathParseItem *expr; |
| | char *pattern; |
| | uint32 patternlen; |
| | uint32 flags; |
| | } like_regex; |
| |
|
| | |
| | Numeric numeric; |
| | bool boolean; |
| | struct |
| | { |
| | uint32 len; |
| | char *val; |
| | } string; |
| | } value; |
| | }; |
| |
|
| | typedef struct JsonPathParseResult |
| | { |
| | JsonPathParseItem *expr; |
| | bool lax; |
| | } JsonPathParseResult; |
| |
|
| | extern JsonPathParseResult *parsejsonpath(const char *str, int len, |
| | struct Node *escontext); |
| |
|
| | extern bool jspConvertRegexFlags(uint32 xflags, int *result, |
| | struct Node *escontext); |
| |
|
| | |
| | |
| | |
| | typedef struct JsonPathVariable |
| | { |
| | char *name; |
| | int namelen; |
| | Oid typid; |
| | int32 typmod; |
| | Datum value; |
| | bool isnull; |
| | } JsonPathVariable; |
| |
|
| |
|
| | |
| | extern bool JsonPathExists(Datum jb, JsonPath *jp, bool *error, List *vars); |
| | extern Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, |
| | bool *empty, bool *error, List *vars, |
| | const char *column_name); |
| | extern JsonbValue *JsonPathValue(Datum jb, JsonPath *jp, bool *empty, |
| | bool *error, List *vars, |
| | const char *column_name); |
| |
|
| | |
| | extern PGDLLIMPORT const TableFuncRoutine JsonbTableRoutine; |
| |
|
| | #endif |
| |
|