mirror of https://github.com/postgres/postgres
SQL 2016 standards among other things contains set of SQL/JSON features for JSON processing inside of relational database. The core of SQL/JSON is JSON path language, allowing access parts of JSON documents and make computations over them. This commit implements partial support JSON path language as separate datatype called "jsonpath". The implementation is partial because it's lacking datetime support and suppression of numeric errors. Missing features will be added later by separate commits. Support of SQL/JSON features requires implementation of separate nodes, and it will be considered in subsequent patches. This commit includes following set of plain functions, allowing to execute jsonpath over jsonb values: * jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]), * jsonb_path_match(jsonb, jsonpath[, jsonb, bool]), * jsonb_path_query(jsonb, jsonpath[, jsonb, bool]), * jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]). * jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]). This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb, jsonpath) correspondingly. These operators will have an index support (implemented in subsequent patches). Catversion bumped, to add new functions and operators. Code was written by Nikita Glukhov and Teodor Sigaev, revised by me. Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work was inspired by Oleg Bartunov. Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkovpull/39/head
parent
893d6f8a1f
commit
72b6460336
@ -0,0 +1,3 @@ |
||||
/jsonpath_gram.h |
||||
/jsonpath_gram.c |
||||
/jsonpath_scan.c |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,480 @@ |
||||
/*------------------------------------------------------------------------- |
||||
* |
||||
* jsonpath_gram.y |
||||
* Grammar definitions for jsonpath datatype |
||||
* |
||||
* Copyright (c) 2019, PostgreSQL Global Development Group |
||||
* |
||||
* IDENTIFICATION |
||||
* src/backend/utils/adt/jsonpath_gram.y |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
|
||||
%{ |
||||
#include "postgres.h" |
||||
|
||||
#include "catalog/pg_collation.h" |
||||
#include "fmgr.h" |
||||
#include "miscadmin.h" |
||||
#include "nodes/pg_list.h" |
||||
#include "regex/regex.h" |
||||
#include "utils/builtins.h" |
||||
#include "utils/jsonpath.h" |
||||
#include "utils/jsonpath_scanner.h" |
||||
|
||||
/* |
||||
* Bison doesn't allocate anything that needs to live across parser calls, |
||||
* so we can easily have it use palloc instead of malloc. This prevents |
||||
* memory leaks if we error out during parsing. Note this only works with |
||||
* bison >= 2.0. However, in bison 1.875 the default is to use alloca() |
||||
* if possible, so there's not really much problem anyhow, at least if |
||||
* you're building with gcc. |
||||
*/ |
||||
#define YYMALLOC palloc |
||||
#define YYFREE pfree |
||||
|
||||
static JsonPathParseItem* |
||||
makeItemType(int type) |
||||
{ |
||||
JsonPathParseItem* v = palloc(sizeof(*v)); |
||||
|
||||
CHECK_FOR_INTERRUPTS(); |
||||
|
||||
v->type = type; |
||||
v->next = NULL; |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeItemString(string *s) |
||||
{ |
||||
JsonPathParseItem *v; |
||||
|
||||
if (s == NULL) |
||||
{ |
||||
v = makeItemType(jpiNull); |
||||
} |
||||
else |
||||
{ |
||||
v = makeItemType(jpiString); |
||||
v->value.string.val = s->val; |
||||
v->value.string.len = s->len; |
||||
} |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeItemVariable(string *s) |
||||
{ |
||||
JsonPathParseItem *v; |
||||
|
||||
v = makeItemType(jpiVariable); |
||||
v->value.string.val = s->val; |
||||
v->value.string.len = s->len; |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeItemKey(string *s) |
||||
{ |
||||
JsonPathParseItem *v; |
||||
|
||||
v = makeItemString(s); |
||||
v->type = jpiKey; |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeItemNumeric(string *s) |
||||
{ |
||||
JsonPathParseItem *v; |
||||
|
||||
v = makeItemType(jpiNumeric); |
||||
v->value.numeric = |
||||
DatumGetNumeric(DirectFunctionCall3(numeric_in, |
||||
CStringGetDatum(s->val), 0, -1)); |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeItemBool(bool val) { |
||||
JsonPathParseItem *v = makeItemType(jpiBool); |
||||
|
||||
v->value.boolean = val; |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeItemBinary(int type, JsonPathParseItem* la, JsonPathParseItem *ra) |
||||
{ |
||||
JsonPathParseItem *v = makeItemType(type); |
||||
|
||||
v->value.args.left = la; |
||||
v->value.args.right = ra; |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeItemUnary(int type, JsonPathParseItem* a) |
||||
{ |
||||
JsonPathParseItem *v; |
||||
|
||||
if (type == jpiPlus && a->type == jpiNumeric && !a->next) |
||||
return a; |
||||
|
||||
if (type == jpiMinus && a->type == jpiNumeric && !a->next) |
||||
{ |
||||
v = makeItemType(jpiNumeric); |
||||
v->value.numeric = |
||||
DatumGetNumeric(DirectFunctionCall1(numeric_uminus, |
||||
NumericGetDatum(a->value.numeric))); |
||||
return v; |
||||
} |
||||
|
||||
v = makeItemType(type); |
||||
|
||||
v->value.arg = a; |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeItemList(List *list) |
||||
{ |
||||
JsonPathParseItem *head, *end; |
||||
ListCell *cell = list_head(list); |
||||
|
||||
head = end = (JsonPathParseItem *) lfirst(cell); |
||||
|
||||
if (!lnext(cell)) |
||||
return head; |
||||
|
||||
/* append items to the end of already existing list */ |
||||
while (end->next) |
||||
end = end->next; |
||||
|
||||
for_each_cell(cell, lnext(cell)) |
||||
{ |
||||
JsonPathParseItem *c = (JsonPathParseItem *) lfirst(cell); |
||||
|
||||
end->next = c; |
||||
end = c; |
||||
} |
||||
|
||||
return head; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeIndexArray(List *list) |
||||
{ |
||||
JsonPathParseItem *v = makeItemType(jpiIndexArray); |
||||
ListCell *cell; |
||||
int i = 0; |
||||
|
||||
Assert(list_length(list) > 0); |
||||
v->value.array.nelems = list_length(list); |
||||
|
||||
v->value.array.elems = palloc(sizeof(v->value.array.elems[0]) * |
||||
v->value.array.nelems); |
||||
|
||||
foreach(cell, list) |
||||
{ |
||||
JsonPathParseItem *jpi = lfirst(cell); |
||||
|
||||
Assert(jpi->type == jpiSubscript); |
||||
|
||||
v->value.array.elems[i].from = jpi->value.args.left; |
||||
v->value.array.elems[i++].to = jpi->value.args.right; |
||||
} |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem* |
||||
makeAny(int first, int last) |
||||
{ |
||||
JsonPathParseItem *v = makeItemType(jpiAny); |
||||
|
||||
v->value.anybounds.first = (first >= 0) ? first : PG_UINT32_MAX; |
||||
v->value.anybounds.last = (last >= 0) ? last : PG_UINT32_MAX; |
||||
|
||||
return v; |
||||
} |
||||
|
||||
static JsonPathParseItem * |
||||
makeItemLikeRegex(JsonPathParseItem *expr, string *pattern, string *flags) |
||||
{ |
||||
JsonPathParseItem *v = makeItemType(jpiLikeRegex); |
||||
int i; |
||||
int cflags = REG_ADVANCED; |
||||
|
||||
v->value.like_regex.expr = expr; |
||||
v->value.like_regex.pattern = pattern->val; |
||||
v->value.like_regex.patternlen = pattern->len; |
||||
v->value.like_regex.flags = 0; |
||||
|
||||
for (i = 0; flags && i < flags->len; i++) |
||||
{ |
||||
switch (flags->val[i]) |
||||
{ |
||||
case 'i': |
||||
v->value.like_regex.flags |= JSP_REGEX_ICASE; |
||||
cflags |= REG_ICASE; |
||||
break; |
||||
case 's': |
||||
v->value.like_regex.flags &= ~JSP_REGEX_MLINE; |
||||
v->value.like_regex.flags |= JSP_REGEX_SLINE; |
||||
cflags |= REG_NEWLINE; |
||||
break; |
||||
case 'm': |
||||
v->value.like_regex.flags &= ~JSP_REGEX_SLINE; |
||||
v->value.like_regex.flags |= JSP_REGEX_MLINE; |
||||
cflags &= ~REG_NEWLINE; |
||||
break; |
||||
case 'x': |
||||
v->value.like_regex.flags |= JSP_REGEX_WSPACE; |
||||
cflags |= REG_EXPANDED; |
||||
break; |
||||
default: |
||||
yyerror(NULL, "unrecognized flag of LIKE_REGEX predicate"); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
/* check regex validity */ |
||||
(void) RE_compile_and_cache(cstring_to_text_with_len(pattern->val, |
||||
pattern->len), |
||||
cflags, DEFAULT_COLLATION_OID); |
||||
|
||||
return v; |
||||
} |
||||
|
||||
%} |
||||
|
||||
/* BISON Declarations */ |
||||
%pure-parser |
||||
%expect 0 |
||||
%name-prefix="jsonpath_yy" |
||||
%error-verbose |
||||
%parse-param {JsonPathParseResult **result} |
||||
|
||||
%union { |
||||
string str; |
||||
List *elems; /* list of JsonPathParseItem */ |
||||
List *indexs; /* list of integers */ |
||||
JsonPathParseItem *value; |
||||
JsonPathParseResult *result; |
||||
JsonPathItemType optype; |
||||
bool boolean; |
||||
int integer; |
||||
} |
||||
|
||||
%token <str> TO_P NULL_P TRUE_P FALSE_P IS_P UNKNOWN_P EXISTS_P |
||||
%token <str> IDENT_P STRING_P NUMERIC_P INT_P VARIABLE_P |
||||
%token <str> OR_P AND_P NOT_P |
||||
%token <str> LESS_P LESSEQUAL_P EQUAL_P NOTEQUAL_P GREATEREQUAL_P GREATER_P |
||||
%token <str> ANY_P STRICT_P LAX_P LAST_P STARTS_P WITH_P LIKE_REGEX_P FLAG_P |
||||
%token <str> ABS_P SIZE_P TYPE_P FLOOR_P DOUBLE_P CEILING_P KEYVALUE_P |
||||
|
||||
%type <result> result |
||||
|
||||
%type <value> scalar_value path_primary expr array_accessor |
||||
any_path accessor_op key predicate delimited_predicate |
||||
index_elem starts_with_initial expr_or_predicate |
||||
|
||||
%type <elems> accessor_expr |
||||
|
||||
%type <indexs> index_list |
||||
|
||||
%type <optype> comp_op method |
||||
|
||||
%type <boolean> mode |
||||
|
||||
%type <str> key_name |
||||
|
||||
%type <integer> any_level |
||||
|
||||
%left OR_P |
||||
%left AND_P |
||||
%right NOT_P |
||||
%left '+' '-' |
||||
%left '*' '/' '%' |
||||
%left UMINUS |
||||
%nonassoc '(' ')' |
||||
|
||||
/* Grammar follows */ |
||||
%% |
||||
|
||||
result: |
||||
mode expr_or_predicate { |
||||
*result = palloc(sizeof(JsonPathParseResult)); |
||||
(*result)->expr = $2; |
||||
(*result)->lax = $1; |
||||
} |
||||
| /* EMPTY */ { *result = NULL; } |
||||
; |
||||
|
||||
expr_or_predicate: |
||||
expr { $$ = $1; } |
||||
| predicate { $$ = $1; } |
||||
; |
||||
|
||||
mode: |
||||
STRICT_P { $$ = false; } |
||||
| LAX_P { $$ = true; } |
||||
| /* EMPTY */ { $$ = true; } |
||||
; |
||||
|
||||
scalar_value: |
||||
STRING_P { $$ = makeItemString(&$1); } |
||||
| NULL_P { $$ = makeItemString(NULL); } |
||||
| TRUE_P { $$ = makeItemBool(true); } |
||||
| FALSE_P { $$ = makeItemBool(false); } |
||||
| NUMERIC_P { $$ = makeItemNumeric(&$1); } |
||||
| INT_P { $$ = makeItemNumeric(&$1); } |
||||
| VARIABLE_P { $$ = makeItemVariable(&$1); } |
||||
; |
||||
|
||||
comp_op: |
||||
EQUAL_P { $$ = jpiEqual; } |
||||
| NOTEQUAL_P { $$ = jpiNotEqual; } |
||||
| LESS_P { $$ = jpiLess; } |
||||
| GREATER_P { $$ = jpiGreater; } |
||||
| LESSEQUAL_P { $$ = jpiLessOrEqual; } |
||||
| GREATEREQUAL_P { $$ = jpiGreaterOrEqual; } |
||||
; |
||||
|
||||
delimited_predicate: |
||||
'(' predicate ')' { $$ = $2; } |
||||
| EXISTS_P '(' expr ')' { $$ = makeItemUnary(jpiExists, $3); } |
||||
; |
||||
|
||||
predicate: |
||||
delimited_predicate { $$ = $1; } |
||||
| expr comp_op expr { $$ = makeItemBinary($2, $1, $3); } |
||||
| predicate AND_P predicate { $$ = makeItemBinary(jpiAnd, $1, $3); } |
||||
| predicate OR_P predicate { $$ = makeItemBinary(jpiOr, $1, $3); } |
||||
| NOT_P delimited_predicate { $$ = makeItemUnary(jpiNot, $2); } |
||||
| '(' predicate ')' IS_P UNKNOWN_P { $$ = makeItemUnary(jpiIsUnknown, $2); } |
||||
| expr STARTS_P WITH_P starts_with_initial |
||||
{ $$ = makeItemBinary(jpiStartsWith, $1, $4); } |
||||
| expr LIKE_REGEX_P STRING_P { $$ = makeItemLikeRegex($1, &$3, NULL); } |
||||
| expr LIKE_REGEX_P STRING_P FLAG_P STRING_P |
||||
{ $$ = makeItemLikeRegex($1, &$3, &$5); } |
||||
; |
||||
|
||||
starts_with_initial: |
||||
STRING_P { $$ = makeItemString(&$1); } |
||||
| VARIABLE_P { $$ = makeItemVariable(&$1); } |
||||
; |
||||
|
||||
path_primary: |
||||
scalar_value { $$ = $1; } |
||||
| '$' { $$ = makeItemType(jpiRoot); } |
||||
| '@' { $$ = makeItemType(jpiCurrent); } |
||||
| LAST_P { $$ = makeItemType(jpiLast); } |
||||
; |
||||
|
||||
accessor_expr: |
||||
path_primary { $$ = list_make1($1); } |
||||
| '(' expr ')' accessor_op { $$ = list_make2($2, $4); } |
||||
| '(' predicate ')' accessor_op { $$ = list_make2($2, $4); } |
||||
| accessor_expr accessor_op { $$ = lappend($1, $2); } |
||||
; |
||||
|
||||
expr: |
||||
accessor_expr { $$ = makeItemList($1); } |
||||
| '(' expr ')' { $$ = $2; } |
||||
| '+' expr %prec UMINUS { $$ = makeItemUnary(jpiPlus, $2); } |
||||
| '-' expr %prec UMINUS { $$ = makeItemUnary(jpiMinus, $2); } |
||||
| expr '+' expr { $$ = makeItemBinary(jpiAdd, $1, $3); } |
||||
| expr '-' expr { $$ = makeItemBinary(jpiSub, $1, $3); } |
||||
| expr '*' expr { $$ = makeItemBinary(jpiMul, $1, $3); } |
||||
| expr '/' expr { $$ = makeItemBinary(jpiDiv, $1, $3); } |
||||
| expr '%' expr { $$ = makeItemBinary(jpiMod, $1, $3); } |
||||
; |
||||
|
||||
index_elem: |
||||
expr { $$ = makeItemBinary(jpiSubscript, $1, NULL); } |
||||
| expr TO_P expr { $$ = makeItemBinary(jpiSubscript, $1, $3); } |
||||
; |
||||
|
||||
index_list: |
||||
index_elem { $$ = list_make1($1); } |
||||
| index_list ',' index_elem { $$ = lappend($1, $3); } |
||||
; |
||||
|
||||
array_accessor: |
||||
'[' '*' ']' { $$ = makeItemType(jpiAnyArray); } |
||||
| '[' index_list ']' { $$ = makeIndexArray($2); } |
||||
; |
||||
|
||||
any_level: |
||||
INT_P { $$ = pg_atoi($1.val, 4, 0); } |
||||
| LAST_P { $$ = -1; } |
||||
; |
||||
|
||||
any_path: |
||||
ANY_P { $$ = makeAny(0, -1); } |
||||
| ANY_P '{' any_level '}' { $$ = makeAny($3, $3); } |
||||
| ANY_P '{' any_level TO_P any_level '}' { $$ = makeAny($3, $5); } |
||||
; |
||||
|
||||
accessor_op: |
||||
'.' key { $$ = $2; } |
||||
| '.' '*' { $$ = makeItemType(jpiAnyKey); } |
||||
| array_accessor { $$ = $1; } |
||||
| '.' any_path { $$ = $2; } |
||||
| '.' method '(' ')' { $$ = makeItemType($2); } |
||||
| '?' '(' predicate ')' { $$ = makeItemUnary(jpiFilter, $3); } |
||||
; |
||||
|
||||
key: |
||||
key_name { $$ = makeItemKey(&$1); } |
||||
; |
||||
|
||||
key_name: |
||||
IDENT_P |
||||
| STRING_P |
||||
| TO_P |
||||
| NULL_P |
||||
| TRUE_P |
||||
| FALSE_P |
||||
| IS_P |
||||
| UNKNOWN_P |
||||
| EXISTS_P |
||||
| STRICT_P |
||||
| LAX_P |
||||
| ABS_P |
||||
| SIZE_P |
||||
| TYPE_P |
||||
| FLOOR_P |
||||
| DOUBLE_P |
||||
| CEILING_P |
||||
| KEYVALUE_P |
||||
| LAST_P |
||||
| STARTS_P |
||||
| WITH_P |
||||
| LIKE_REGEX_P |
||||
| FLAG_P |
||||
; |
||||
|
||||
method: |
||||
ABS_P { $$ = jpiAbs; } |
||||
| SIZE_P { $$ = jpiSize; } |
||||
| TYPE_P { $$ = jpiType; } |
||||
| FLOOR_P { $$ = jpiFloor; } |
||||
| DOUBLE_P { $$ = jpiDouble; } |
||||
| CEILING_P { $$ = jpiCeiling; } |
||||
| KEYVALUE_P { $$ = jpiKeyValue; } |
||||
; |
||||
%% |
||||
|
@ -0,0 +1,638 @@ |
||||
/*------------------------------------------------------------------------- |
||||
* |
||||
* jsonpath_scan.l |
||||
* Lexical parser for jsonpath datatype |
||||
* |
||||
* Copyright (c) 2019, PostgreSQL Global Development Group |
||||
* |
||||
* IDENTIFICATION |
||||
* src/backend/utils/adt/jsonpath_scan.l |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
|
||||
%{ |
||||
#include "postgres.h" |
||||
|
||||
#include "mb/pg_wchar.h" |
||||
#include "nodes/pg_list.h" |
||||
#include "utils/jsonpath_scanner.h" |
||||
|
||||
static string scanstring; |
||||
|
||||
/* No reason to constrain amount of data slurped */ |
||||
/* #define YY_READ_BUF_SIZE 16777216 */ |
||||
|
||||
/* Handles to the buffer that the lexer uses internally */ |
||||
static YY_BUFFER_STATE scanbufhandle; |
||||
static char *scanbuf; |
||||
static int scanbuflen; |
||||
|
||||
static void addstring(bool init, char *s, int l); |
||||
static void addchar(bool init, char s); |
||||
static int checkSpecialVal(void); /* examine scanstring for the special |
||||
* value */ |
||||
|
||||
static void parseUnicode(char *s, int l); |
||||
static void parseHexChars(char *s, int l); |
||||
|
||||
/* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */ |
||||
#undef fprintf |
||||
#define fprintf(file, fmt, msg) fprintf_to_ereport(fmt, msg) |
||||
|
||||
static void |
||||
fprintf_to_ereport(const char *fmt, const char *msg) |
||||
{ |
||||
ereport(ERROR, (errmsg_internal("%s", msg))); |
||||
} |
||||
|
||||
#define yyerror jsonpath_yyerror |
||||
%} |
||||
|
||||
%option 8bit |
||||
%option never-interactive |
||||
%option nodefault |
||||
%option noinput |
||||
%option nounput |
||||
%option noyywrap |
||||
%option warn |
||||
%option prefix="jsonpath_yy" |
||||
%option bison-bridge |
||||
%option noyyalloc |
||||
%option noyyrealloc |
||||
%option noyyfree |
||||
|
||||
%x xQUOTED |
||||
%x xNONQUOTED |
||||
%x xVARQUOTED |
||||
%x xSINGLEQUOTED |
||||
%x xCOMMENT |
||||
|
||||
special [\?\%\$\.\[\]\{\}\(\)\|\&\!\=\<\>\@\#\,\*:\-\+\/] |
||||
any [^\?\%\$\.\[\]\{\}\(\)\|\&\!\=\<\>\@\#\,\*:\-\+\/\\\"\' \t\n\r\f] |
||||
blank [ \t\n\r\f] |
||||
hex_dig [0-9A-Fa-f] |
||||
unicode \\u({hex_dig}{4}|\{{hex_dig}{1,6}\}) |
||||
hex_char \\x{hex_dig}{2} |
||||
|
||||
|
||||
%% |
||||
|
||||
<INITIAL>\&\& { return AND_P; } |
||||
|
||||
<INITIAL>\|\| { return OR_P; } |
||||
|
||||
<INITIAL>\! { return NOT_P; } |
||||
|
||||
<INITIAL>\*\* { return ANY_P; } |
||||
|
||||
<INITIAL>\< { return LESS_P; } |
||||
|
||||
<INITIAL>\<\= { return LESSEQUAL_P; } |
||||
|
||||
<INITIAL>\=\= { return EQUAL_P; } |
||||
|
||||
<INITIAL>\<\> { return NOTEQUAL_P; } |
||||
|
||||
<INITIAL>\!\= { return NOTEQUAL_P; } |
||||
|
||||
<INITIAL>\>\= { return GREATEREQUAL_P; } |
||||
|
||||
<INITIAL>\> { return GREATER_P; } |
||||
|
||||
<INITIAL>\${any}+ { |
||||
addstring(true, yytext + 1, yyleng - 1); |
||||
addchar(false, '\0'); |
||||
yylval->str = scanstring; |
||||
return VARIABLE_P; |
||||
} |
||||
|
||||
<INITIAL>\$\" { |
||||
addchar(true, '\0'); |
||||
BEGIN xVARQUOTED; |
||||
} |
||||
|
||||
<INITIAL>{special} { return *yytext; } |
||||
|
||||
<INITIAL>{blank}+ { /* ignore */ } |
||||
|
||||
<INITIAL>\/\* { |
||||
addchar(true, '\0'); |
||||
BEGIN xCOMMENT; |
||||
} |
||||
|
||||
<INITIAL>[0-9]+(\.[0-9]+)?[eE][+-]?[0-9]+ /* float */ { |
||||
addstring(true, yytext, yyleng); |
||||
addchar(false, '\0'); |
||||
yylval->str = scanstring; |
||||
return NUMERIC_P; |
||||
} |
||||
|
||||
<INITIAL>\.[0-9]+[eE][+-]?[0-9]+ /* float */ { |
||||
addstring(true, yytext, yyleng); |
||||
addchar(false, '\0'); |
||||
yylval->str = scanstring; |
||||
return NUMERIC_P; |
||||
} |
||||
|
||||
<INITIAL>([0-9]+)?\.[0-9]+ { |
||||
addstring(true, yytext, yyleng); |
||||
addchar(false, '\0'); |
||||
yylval->str = scanstring; |
||||
return NUMERIC_P; |
||||
} |
||||
|
||||
<INITIAL>[0-9]+ { |
||||
addstring(true, yytext, yyleng); |
||||
addchar(false, '\0'); |
||||
yylval->str = scanstring; |
||||
return INT_P; |
||||
} |
||||
|
||||
<INITIAL>{any}+ { |
||||
addstring(true, yytext, yyleng); |
||||
BEGIN xNONQUOTED; |
||||
} |
||||
|
||||
<INITIAL>\" { |
||||
addchar(true, '\0'); |
||||
BEGIN xQUOTED; |
||||
} |
||||
|
||||
<INITIAL>\' { |
||||
addchar(true, '\0'); |
||||
BEGIN xSINGLEQUOTED; |
||||
} |
||||
|
||||
<INITIAL>\\ { |
||||
yyless(0); |
||||
addchar(true, '\0'); |
||||
BEGIN xNONQUOTED; |
||||
} |
||||
|
||||
<xNONQUOTED>{any}+ { |
||||
addstring(false, yytext, yyleng); |
||||
} |
||||
|
||||
<xNONQUOTED>{blank}+ { |
||||
yylval->str = scanstring; |
||||
BEGIN INITIAL; |
||||
return checkSpecialVal(); |
||||
} |
||||
|
||||
|
||||
<xNONQUOTED>\/\* { |
||||
yylval->str = scanstring; |
||||
BEGIN xCOMMENT; |
||||
} |
||||
|
||||
<xNONQUOTED>({special}|\"|\') { |
||||
yylval->str = scanstring; |
||||
yyless(0); |
||||
BEGIN INITIAL; |
||||
return checkSpecialVal(); |
||||
} |
||||
|
||||
<xNONQUOTED><<EOF>> { |
||||
yylval->str = scanstring; |
||||
BEGIN INITIAL; |
||||
return checkSpecialVal(); |
||||
} |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\[\"\'\\] { addchar(false, yytext[1]); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\b { addchar(false, '\b'); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\f { addchar(false, '\f'); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\n { addchar(false, '\n'); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\r { addchar(false, '\r'); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\t { addchar(false, '\t'); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\v { addchar(false, '\v'); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>{unicode}+ { parseUnicode(yytext, yyleng); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>{hex_char}+ { parseHexChars(yytext, yyleng); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\x { yyerror(NULL, "Hex character sequence is invalid"); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\u { yyerror(NULL, "Unicode sequence is invalid"); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\. { yyerror(NULL, "Escape sequence is invalid"); } |
||||
|
||||
<xNONQUOTED,xQUOTED,xVARQUOTED,xSINGLEQUOTED>\\ { yyerror(NULL, "Unexpected end after backslash"); } |
||||
|
||||
<xQUOTED,xVARQUOTED,xSINGLEQUOTED><<EOF>> { yyerror(NULL, "Unexpected end of quoted string"); } |
||||
|
||||
<xQUOTED>\" { |
||||
yylval->str = scanstring; |
||||
BEGIN INITIAL; |
||||
return STRING_P; |
||||
} |
||||
|
||||
<xVARQUOTED>\" { |
||||
yylval->str = scanstring; |
||||
BEGIN INITIAL; |
||||
return VARIABLE_P; |
||||
} |
||||
|
||||
<xSINGLEQUOTED>\' { |
||||
yylval->str = scanstring; |
||||
BEGIN INITIAL; |
||||
return STRING_P; |
||||
} |
||||
|
||||
<xQUOTED,xVARQUOTED>[^\\\"]+ { addstring(false, yytext, yyleng); } |
||||
|
||||
<xSINGLEQUOTED>[^\\\']+ { addstring(false, yytext, yyleng); } |
||||
|
||||
<INITIAL><<EOF>> { yyterminate(); } |
||||
|
||||
<xCOMMENT>\*\/ { BEGIN INITIAL; } |
||||
|
||||
<xCOMMENT>[^\*]+ { } |
||||
|
||||
<xCOMMENT>\* { } |
||||
|
||||
<xCOMMENT><<EOF>> { yyerror(NULL, "Unexpected end of comment"); } |
||||
|
||||
%% |
||||
|
||||
void |
||||
jsonpath_yyerror(JsonPathParseResult **result, const char *message) |
||||
{ |
||||
if (*yytext == YY_END_OF_BUFFER_CHAR) |
||||
{ |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_SYNTAX_ERROR), |
||||
errmsg("bad jsonpath representation"), |
||||
/* translator: %s is typically "syntax error" */ |
||||
errdetail("%s at end of input", message))); |
||||
} |
||||
else |
||||
{ |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_SYNTAX_ERROR), |
||||
errmsg("bad jsonpath representation"), |
||||
/* translator: first %s is typically "syntax error" */ |
||||
errdetail("%s at or near \"%s\"", message, yytext))); |
||||
} |
||||
} |
||||
|
||||
typedef struct keyword |
||||
{ |
||||
int16 len; |
||||
bool lowercase; |
||||
int val; |
||||
char *keyword; |
||||
} keyword; |
||||
|
||||
/* |
||||
* Array of key words should be sorted by length and then |
||||
* alphabetical order |
||||
*/ |
||||
|
||||
static keyword keywords[] = { |
||||
{ 2, false, IS_P, "is"}, |
||||
{ 2, false, TO_P, "to"}, |
||||
{ 3, false, ABS_P, "abs"}, |
||||
{ 3, false, LAX_P, "lax"}, |
||||
{ 4, false, FLAG_P, "flag"}, |
||||
{ 4, false, LAST_P, "last"}, |
||||
{ 4, true, NULL_P, "null"}, |
||||
{ 4, false, SIZE_P, "size"}, |
||||
{ 4, true, TRUE_P, "true"}, |
||||
{ 4, false, TYPE_P, "type"}, |
||||
{ 4, false, WITH_P, "with"}, |
||||
{ 5, true, FALSE_P, "false"}, |
||||
{ 5, false, FLOOR_P, "floor"}, |
||||
{ 6, false, DOUBLE_P, "double"}, |
||||
{ 6, false, EXISTS_P, "exists"}, |
||||
{ 6, false, STARTS_P, "starts"}, |
||||
{ 6, false, STRICT_P, "strict"}, |
||||
{ 7, false, CEILING_P, "ceiling"}, |
||||
{ 7, false, UNKNOWN_P, "unknown"}, |
||||
{ 8, false, KEYVALUE_P, "keyvalue"}, |
||||
{ 10,false, LIKE_REGEX_P, "like_regex"}, |
||||
}; |
||||
|
||||
static int |
||||
checkSpecialVal() |
||||
{ |
||||
int res = IDENT_P; |
||||
int diff; |
||||
keyword *StopLow = keywords, |
||||
*StopHigh = keywords + lengthof(keywords), |
||||
*StopMiddle; |
||||
|
||||
if (scanstring.len > keywords[lengthof(keywords) - 1].len) |
||||
return res; |
||||
|
||||
while(StopLow < StopHigh) |
||||
{ |
||||
StopMiddle = StopLow + ((StopHigh - StopLow) >> 1); |
||||
|
||||
if (StopMiddle->len == scanstring.len) |
||||
diff = pg_strncasecmp(StopMiddle->keyword, scanstring.val, |
||||
scanstring.len); |
||||
else |
||||
diff = StopMiddle->len - scanstring.len; |
||||
|
||||
if (diff < 0) |
||||
StopLow = StopMiddle + 1; |
||||
else if (diff > 0) |
||||
StopHigh = StopMiddle; |
||||
else |
||||
{ |
||||
if (StopMiddle->lowercase) |
||||
diff = strncmp(StopMiddle->keyword, scanstring.val, |
||||
scanstring.len); |
||||
|
||||
if (diff == 0) |
||||
res = StopMiddle->val; |
||||
|
||||
break; |
||||
} |
||||
} |
||||
|
||||
return res; |
||||
} |
||||
|
||||
/* |
||||
* Called before any actual parsing is done |
||||
*/ |
||||
static void |
||||
jsonpath_scanner_init(const char *str, int slen) |
||||
{ |
||||
if (slen <= 0) |
||||
slen = strlen(str); |
||||
|
||||
/* |
||||
* Might be left over after ereport() |
||||
*/ |
||||
yy_init_globals(); |
||||
|
||||
/* |
||||
* Make a scan buffer with special termination needed by flex. |
||||
*/ |
||||
|
||||
scanbuflen = slen; |
||||
scanbuf = palloc(slen + 2); |
||||
memcpy(scanbuf, str, slen); |
||||
scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR; |
||||
scanbufhandle = yy_scan_buffer(scanbuf, slen + 2); |
||||
|
||||
BEGIN(INITIAL); |
||||
} |
||||
|
||||
|
||||
/* |
||||
* Called after parsing is done to clean up after jsonpath_scanner_init() |
||||
*/ |
||||
static void |
||||
jsonpath_scanner_finish(void) |
||||
{ |
||||
yy_delete_buffer(scanbufhandle); |
||||
pfree(scanbuf); |
||||
} |
||||
|
||||
static void |
||||
addstring(bool init, char *s, int l) |
||||
{ |
||||
if (init) |
||||
{ |
||||
scanstring.total = 32; |
||||
scanstring.val = palloc(scanstring.total); |
||||
scanstring.len = 0; |
||||
} |
||||
|
||||
if (s && l) |
||||
{ |
||||
while(scanstring.len + l + 1 >= scanstring.total) |
||||
{ |
||||
scanstring.total *= 2; |
||||
scanstring.val = repalloc(scanstring.val, scanstring.total); |
||||
} |
||||
|
||||
memcpy(scanstring.val + scanstring.len, s, l); |
||||
scanstring.len += l; |
||||
} |
||||
} |
||||
|
||||
static void |
||||
addchar(bool init, char s) |
||||
{ |
||||
if (init) |
||||
{ |
||||
scanstring.total = 32; |
||||
scanstring.val = palloc(scanstring.total); |
||||
scanstring.len = 0; |
||||
} |
||||
else if(scanstring.len + 1 >= scanstring.total) |
||||
{ |
||||
scanstring.total *= 2; |
||||
scanstring.val = repalloc(scanstring.val, scanstring.total); |
||||
} |
||||
|
||||
scanstring.val[ scanstring.len ] = s; |
||||
if (s != '\0') |
||||
scanstring.len++; |
||||
} |
||||
|
||||
JsonPathParseResult * |
||||
parsejsonpath(const char *str, int len) |
||||
{ |
||||
JsonPathParseResult *parseresult; |
||||
|
||||
jsonpath_scanner_init(str, len); |
||||
|
||||
if (jsonpath_yyparse((void*)&parseresult) != 0) |
||||
jsonpath_yyerror(NULL, "bugus input"); |
||||
|
||||
jsonpath_scanner_finish(); |
||||
|
||||
return parseresult; |
||||
} |
||||
|
||||
static int |
||||
hexval(char c) |
||||
{ |
||||
if (c >= '0' && c <= '9') |
||||
return c - '0'; |
||||
if (c >= 'a' && c <= 'f') |
||||
return c - 'a' + 0xA; |
||||
if (c >= 'A' && c <= 'F') |
||||
return c - 'A' + 0xA; |
||||
elog(ERROR, "invalid hexadecimal digit"); |
||||
return 0; /* not reached */ |
||||
} |
||||
|
||||
static void |
||||
addUnicodeChar(int ch) |
||||
{ |
||||
/* |
||||
* For UTF8, replace the escape sequence by the actual |
||||
* utf8 character in lex->strval. Do this also for other |
||||
* encodings if the escape designates an ASCII character, |
||||
* otherwise raise an error. |
||||
*/ |
||||
|
||||
if (ch == 0) |
||||
{ |
||||
/* We can't allow this, since our TEXT type doesn't */ |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_UNTRANSLATABLE_CHARACTER), |
||||
errmsg("unsupported Unicode escape sequence"), |
||||
errdetail("\\u0000 cannot be converted to text."))); |
||||
} |
||||
else if (GetDatabaseEncoding() == PG_UTF8) |
||||
{ |
||||
char utf8str[5]; |
||||
int utf8len; |
||||
|
||||
unicode_to_utf8(ch, (unsigned char *) utf8str); |
||||
utf8len = pg_utf_mblen((unsigned char *) utf8str); |
||||
addstring(false, utf8str, utf8len); |
||||
} |
||||
else if (ch <= 0x007f) |
||||
{ |
||||
/* |
||||
* This is the only way to designate things like a |
||||
* form feed character in JSON, so it's useful in all |
||||
* encodings. |
||||
*/ |
||||
addchar(false, (char) ch); |
||||
} |
||||
else |
||||
{ |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
||||
errmsg("invalid input syntax for type jsonpath"), |
||||
errdetail("Unicode escape values cannot be used for code " |
||||
"point values above 007F when the server encoding " |
||||
"is not UTF8."))); |
||||
} |
||||
} |
||||
|
||||
static void |
||||
addUnicode(int ch, int *hi_surrogate) |
||||
{ |
||||
if (ch >= 0xd800 && ch <= 0xdbff) |
||||
{ |
||||
if (*hi_surrogate != -1) |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
||||
errmsg("invalid input syntax for type jsonpath"), |
||||
errdetail("Unicode high surrogate must not follow " |
||||
"a high surrogate."))); |
||||
*hi_surrogate = (ch & 0x3ff) << 10; |
||||
return; |
||||
} |
||||
else if (ch >= 0xdc00 && ch <= 0xdfff) |
||||
{ |
||||
if (*hi_surrogate == -1) |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
||||
errmsg("invalid input syntax for type jsonpath"), |
||||
errdetail("Unicode low surrogate must follow a high " |
||||
"surrogate."))); |
||||
ch = 0x10000 + *hi_surrogate + (ch & 0x3ff); |
||||
*hi_surrogate = -1; |
||||
} |
||||
else if (*hi_surrogate != -1) |
||||
{ |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
||||
errmsg("invalid input syntax for type jsonpath"), |
||||
errdetail("Unicode low surrogate must follow a high " |
||||
"surrogate."))); |
||||
} |
||||
|
||||
addUnicodeChar(ch); |
||||
} |
||||
|
||||
/* |
||||
* parseUnicode was adopted from json_lex_string() in |
||||
* src/backend/utils/adt/json.c |
||||
*/ |
||||
static void |
||||
parseUnicode(char *s, int l) |
||||
{ |
||||
int i; |
||||
int hi_surrogate = -1; |
||||
|
||||
for (i = 2; i < l; i += 2) /* skip '\u' */ |
||||
{ |
||||
int ch = 0; |
||||
int j; |
||||
|
||||
if (s[i] == '{') /* parse '\u{XX...}' */ |
||||
{ |
||||
while (s[++i] != '}' && i < l) |
||||
ch = (ch << 4) | hexval(s[i]); |
||||
i++; /* ski p '}' */ |
||||
} |
||||
else /* parse '\uXXXX' */ |
||||
{ |
||||
for (j = 0; j < 4 && i < l; j++) |
||||
ch = (ch << 4) | hexval(s[i++]); |
||||
} |
||||
|
||||
addUnicode(ch, &hi_surrogate); |
||||
} |
||||
|
||||
if (hi_surrogate != -1) |
||||
{ |
||||
ereport(ERROR, |
||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
||||
errmsg("invalid input syntax for type jsonpath"), |
||||
errdetail("Unicode low surrogate must follow a high " |
||||
"surrogate."))); |
||||
} |
||||
} |
||||
|
||||
static void |
||||
parseHexChars(char *s, int l) |
||||
{ |
||||
int i; |
||||
|
||||
Assert(l % 4 /* \xXX */ == 0); |
||||
|
||||
for (i = 0; i < l / 4; i++) |
||||
{ |
||||
int ch = (hexval(s[i * 4 + 2]) << 4) | hexval(s[i * 4 + 3]); |
||||
|
||||
addUnicodeChar(ch); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* Interface functions to make flex use palloc() instead of malloc(). |
||||
* It'd be better to make these static, but flex insists otherwise. |
||||
*/ |
||||
|
||||
void * |
||||
jsonpath_yyalloc(yy_size_t bytes) |
||||
{ |
||||
return palloc(bytes); |
||||
} |
||||
|
||||
void * |
||||
jsonpath_yyrealloc(void *ptr, yy_size_t bytes) |
||||
{ |
||||
if (ptr) |
||||
return repalloc(ptr, bytes); |
||||
else |
||||
return palloc(bytes); |
||||
} |
||||
|
||||
void |
||||
jsonpath_yyfree(void *ptr) |
||||
{ |
||||
if (ptr) |
||||
pfree(ptr); |
||||
} |
||||
|
@ -0,0 +1,245 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* jsonpath.h |
||||
* Definitions for jsonpath datatype |
||||
* |
||||
* Copyright (c) 2019, PostgreSQL Global Development Group |
||||
* |
||||
* IDENTIFICATION |
||||
* src/include/utils/jsonpath.h |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
|
||||
#ifndef JSONPATH_H |
||||
#define JSONPATH_H |
||||
|
||||
#include "fmgr.h" |
||||
#include "utils/jsonb.h" |
||||
#include "nodes/pg_list.h" |
||||
|
||||
typedef struct |
||||
{ |
||||
int32 vl_len_; /* varlena header (do not touch directly!) */ |
||||
uint32 header; /* version and flags (see below) */ |
||||
char data[FLEXIBLE_ARRAY_MEMBER]; |
||||
} JsonPath; |
||||
|
||||
#define JSONPATH_VERSION (0x01) |
||||
#define JSONPATH_LAX (0x80000000) |
||||
#define JSONPATH_HDRSZ (offsetof(JsonPath, data)) |
||||
|
||||
#define DatumGetJsonPathP(d) ((JsonPath *) DatumGetPointer(PG_DETOAST_DATUM(d))) |
||||
#define DatumGetJsonPathPCopy(d) ((JsonPath *) DatumGetPointer(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) |
||||
|
||||
/*
|
||||
* All node's type of jsonpath expression |
||||
*/ |
||||
typedef enum JsonPathItemType |
||||
{ |
||||
jpiNull = jbvNull, /* NULL literal */ |
||||
jpiString = jbvString, /* string literal */ |
||||
jpiNumeric = jbvNumeric, /* numeric literal */ |
||||
jpiBool = jbvBool, /* boolean literal: TRUE or FALSE */ |
||||
jpiAnd, /* predicate && predicate */ |
||||
jpiOr, /* predicate || predicate */ |
||||
jpiNot, /* ! predicate */ |
||||
jpiIsUnknown, /* (predicate) IS UNKNOWN */ |
||||
jpiEqual, /* expr == expr */ |
||||
jpiNotEqual, /* expr != expr */ |
||||
jpiLess, /* expr < expr */ |
||||
jpiGreater, /* expr > expr */ |
||||
jpiLessOrEqual, /* expr <= expr */ |
||||
jpiGreaterOrEqual, /* expr >= expr */ |
||||
jpiAdd, /* expr + expr */ |
||||
jpiSub, /* expr - expr */ |
||||
jpiMul, /* expr * expr */ |
||||
jpiDiv, /* expr / expr */ |
||||
jpiMod, /* expr % expr */ |
||||
jpiPlus, /* + expr */ |
||||
jpiMinus, /* - expr */ |
||||
jpiAnyArray, /* [*] */ |
||||
jpiAnyKey, /* .* */ |
||||
jpiIndexArray, /* [subscript, ...] */ |
||||
jpiAny, /* .** */ |
||||
jpiKey, /* .key */ |
||||
jpiCurrent, /* @ */ |
||||
jpiRoot, /* $ */ |
||||
jpiVariable, /* $variable */ |
||||
jpiFilter, /* ? (predicate) */ |
||||
jpiExists, /* EXISTS (expr) predicate */ |
||||
jpiType, /* .type() item method */ |
||||
jpiSize, /* .size() item method */ |
||||
jpiAbs, /* .abs() item method */ |
||||
jpiFloor, /* .floor() item method */ |
||||
jpiCeiling, /* .ceiling() item method */ |
||||
jpiDouble, /* .double() item method */ |
||||
jpiKeyValue, /* .keyvalue() item method */ |
||||
jpiSubscript, /* array subscript: 'expr' or 'expr TO expr' */ |
||||
jpiLast, /* LAST array subscript */ |
||||
jpiStartsWith, /* STARTS WITH predicate */ |
||||
jpiLikeRegex, /* LIKE_REGEX predicate */ |
||||
} JsonPathItemType; |
||||
|
||||
/* XQuery regex mode flags for LIKE_REGEX predicate */ |
||||
#define JSP_REGEX_ICASE 0x01 /* i flag, case insensitive */ |
||||
#define JSP_REGEX_SLINE 0x02 /* s flag, single-line mode */ |
||||
#define JSP_REGEX_MLINE 0x04 /* m flag, multi-line mode */ |
||||
#define JSP_REGEX_WSPACE 0x08 /* x flag, expanded syntax */ |
||||
|
||||
/*
|
||||
* Support functions to parse/construct binary value. |
||||
* Unlike many other representation of expression the first/main |
||||
* node is not an operation but left operand of expression. That |
||||
* allows to implement cheep follow-path descending in jsonb |
||||
* structure and then execute operator with right operand |
||||
*/ |
||||
|
||||
typedef struct JsonPathItem |
||||
{ |
||||
JsonPathItemType type; |
||||
|
||||
/* position form base to next node */ |
||||
int32 nextPos; |
||||
|
||||
/*
|
||||
* pointer into JsonPath value to current node, all positions of current |
||||
* are relative to this base |
||||
*/ |
||||
char *base; |
||||
|
||||
union |
||||
{ |
||||
/* classic operator with two operands: and, or etc */ |
||||
struct |
||||
{ |
||||
int32 left; |
||||
int32 right; |
||||
} args; |
||||
|
||||
/* any unary operation */ |
||||
int32 arg; |
||||
|
||||
/* storage for jpiIndexArray: indexes of array */ |
||||
struct |
||||
{ |
||||
int32 nelems; |
||||
struct |
||||
{ |
||||
int32 from; |
||||
int32 to; |
||||
} *elems; |
||||
} array; |
||||
|
||||
/* jpiAny: levels */ |
||||
struct |
||||
{ |
||||
uint32 first; |
||||
uint32 last; |
||||
} anybounds; |
||||
|
||||
struct |
||||
{ |
||||
char *data; /* for bool, numeric and string/key */ |
||||
int32 datalen; /* filled only for string/key */ |
||||
} 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 const char *jspOperationName(JsonPathItemType type); |
||||
|
||||
/*
|
||||
* Parsing support data structures. |
||||
*/ |
||||
|
||||
typedef struct JsonPathParseItem JsonPathParseItem; |
||||
|
||||
struct JsonPathParseItem |
||||
{ |
||||
JsonPathItemType type; |
||||
JsonPathParseItem *next; /* next in path */ |
||||
|
||||
union |
||||
{ |
||||
|
||||
/* classic operator with two operands: and, or etc */ |
||||
struct |
||||
{ |
||||
JsonPathParseItem *left; |
||||
JsonPathParseItem *right; |
||||
} args; |
||||
|
||||
/* any unary operation */ |
||||
JsonPathParseItem *arg; |
||||
|
||||
/* storage for jpiIndexArray: indexes of array */ |
||||
struct |
||||
{ |
||||
int nelems; |
||||
struct |
||||
{ |
||||
JsonPathParseItem *from; |
||||
JsonPathParseItem *to; |
||||
} *elems; |
||||
} array; |
||||
|
||||
/* jpiAny: levels */ |
||||
struct |
||||
{ |
||||
uint32 first; |
||||
uint32 last; |
||||
} anybounds; |
||||
|
||||
struct |
||||
{ |
||||
JsonPathParseItem *expr; |
||||
char *pattern; /* could not be not null-terminated */ |
||||
uint32 patternlen; |
||||
uint32 flags; |
||||
} like_regex; |
||||
|
||||
/* scalars */ |
||||
Numeric numeric; |
||||
bool boolean; |
||||
struct |
||||
{ |
||||
uint32 len; |
||||
char *val; /* could not be not null-terminated */ |
||||
} string; |
||||
} value; |
||||
}; |
||||
|
||||
typedef struct JsonPathParseResult |
||||
{ |
||||
JsonPathParseItem *expr; |
||||
bool lax; |
||||
} JsonPathParseResult; |
||||
|
||||
extern JsonPathParseResult *parsejsonpath(const char *str, int len); |
||||
|
||||
#endif |
@ -0,0 +1,32 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* jsonpath_scanner.h |
||||
* Definitions for jsonpath scanner & parser |
||||
* |
||||
* Portions Copyright (c) 2019, PostgreSQL Global Development Group |
||||
* |
||||
* src/include/utils/jsonpath_scanner.h |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
|
||||
#ifndef JSONPATH_SCANNER_H |
||||
#define JSONPATH_SCANNER_H |
||||
|
||||
/* struct string is shared between scan and gram */ |
||||
typedef struct string |
||||
{ |
||||
char *val; |
||||
int len; |
||||
int total; |
||||
} string; |
||||
|
||||
#include "utils/jsonpath.h" |
||||
#include "utils/jsonpath_gram.h" |
||||
|
||||
/* flex 2.5.4 doesn't bother with a decl for this */ |
||||
extern int jsonpath_yylex(YYSTYPE *yylval_param); |
||||
extern int jsonpath_yyparse(JsonPathParseResult **result); |
||||
extern void jsonpath_yyerror(JsonPathParseResult **result, const char *message); |
||||
|
||||
#endif |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,806 @@ |
||||
--jsonpath io |
||||
select ''::jsonpath; |
||||
ERROR: invalid input syntax for jsonpath: "" |
||||
LINE 1: select ''::jsonpath; |
||||
^ |
||||
select '$'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$ |
||||
(1 row) |
||||
|
||||
select 'strict $'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
strict $ |
||||
(1 row) |
||||
|
||||
select 'lax $'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$ |
||||
(1 row) |
||||
|
||||
select '$.a'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$."a" |
||||
(1 row) |
||||
|
||||
select '$.a.v'::jsonpath; |
||||
jsonpath |
||||
----------- |
||||
$."a"."v" |
||||
(1 row) |
||||
|
||||
select '$.a.*'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$."a".* |
||||
(1 row) |
||||
|
||||
select '$.*[*]'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$.*[*] |
||||
(1 row) |
||||
|
||||
select '$.a[*]'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$."a"[*] |
||||
(1 row) |
||||
|
||||
select '$.a[*][*]'::jsonpath; |
||||
jsonpath |
||||
------------- |
||||
$."a"[*][*] |
||||
(1 row) |
||||
|
||||
select '$[*]'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$[*] |
||||
(1 row) |
||||
|
||||
select '$[0]'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$[0] |
||||
(1 row) |
||||
|
||||
select '$[*][0]'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$[*][0] |
||||
(1 row) |
||||
|
||||
select '$[*].a'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$[*]."a" |
||||
(1 row) |
||||
|
||||
select '$[*][0].a.b'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$[*][0]."a"."b" |
||||
(1 row) |
||||
|
||||
select '$.a.**.b'::jsonpath; |
||||
jsonpath |
||||
-------------- |
||||
$."a".**."b" |
||||
(1 row) |
||||
|
||||
select '$.a.**{2}.b'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$."a".**{2}."b" |
||||
(1 row) |
||||
|
||||
select '$.a.**{2 to 2}.b'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$."a".**{2}."b" |
||||
(1 row) |
||||
|
||||
select '$.a.**{2 to 5}.b'::jsonpath; |
||||
jsonpath |
||||
---------------------- |
||||
$."a".**{2 to 5}."b" |
||||
(1 row) |
||||
|
||||
select '$.a.**{0 to 5}.b'::jsonpath; |
||||
jsonpath |
||||
---------------------- |
||||
$."a".**{0 to 5}."b" |
||||
(1 row) |
||||
|
||||
select '$.a.**{5 to last}.b'::jsonpath; |
||||
jsonpath |
||||
------------------------- |
||||
$."a".**{5 to last}."b" |
||||
(1 row) |
||||
|
||||
select '$.a.**{last}.b'::jsonpath; |
||||
jsonpath |
||||
-------------------- |
||||
$."a".**{last}."b" |
||||
(1 row) |
||||
|
||||
select '$.a.**{last to 5}.b'::jsonpath; |
||||
jsonpath |
||||
------------------------- |
||||
$."a".**{last to 5}."b" |
||||
(1 row) |
||||
|
||||
select '$+1'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
($ + 1) |
||||
(1 row) |
||||
|
||||
select '$-1'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
($ - 1) |
||||
(1 row) |
||||
|
||||
select '$--+1'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
($ - -1) |
||||
(1 row) |
||||
|
||||
select '$.a/+-1'::jsonpath; |
||||
jsonpath |
||||
-------------- |
||||
($."a" / -1) |
||||
(1 row) |
||||
|
||||
select '1 * 2 + 4 % -3 != false'::jsonpath; |
||||
jsonpath |
||||
--------------------------- |
||||
(1 * 2 + 4 % -3 != false) |
||||
(1 row) |
||||
|
||||
select '"\b\f\r\n\t\v\"\''\\"'::jsonpath; |
||||
jsonpath |
||||
------------------------- |
||||
"\b\f\r\n\t\u000b\"'\\" |
||||
(1 row) |
||||
|
||||
select '''\b\f\r\n\t\v\"\''\\'''::jsonpath; |
||||
jsonpath |
||||
------------------------- |
||||
"\b\f\r\n\t\u000b\"'\\" |
||||
(1 row) |
||||
|
||||
select '"\x50\u0067\u{53}\u{051}\u{00004C}"'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
"PgSQL" |
||||
(1 row) |
||||
|
||||
select '''\x50\u0067\u{53}\u{051}\u{00004C}'''::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
"PgSQL" |
||||
(1 row) |
||||
|
||||
select '$.foo\x50\u0067\u{53}\u{051}\u{00004C}\t\"bar'::jsonpath; |
||||
jsonpath |
||||
--------------------- |
||||
$."fooPgSQL\t\"bar" |
||||
(1 row) |
||||
|
||||
select '$.g ? ($.a == 1)'::jsonpath; |
||||
jsonpath |
||||
-------------------- |
||||
$."g"?($."a" == 1) |
||||
(1 row) |
||||
|
||||
select '$.g ? (@ == 1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$."g"?(@ == 1) |
||||
(1 row) |
||||
|
||||
select '$.g ? (@.a == 1)'::jsonpath; |
||||
jsonpath |
||||
-------------------- |
||||
$."g"?(@."a" == 1) |
||||
(1 row) |
||||
|
||||
select '$.g ? (@.a == 1 || @.a == 4)'::jsonpath; |
||||
jsonpath |
||||
---------------------------------- |
||||
$."g"?(@."a" == 1 || @."a" == 4) |
||||
(1 row) |
||||
|
||||
select '$.g ? (@.a == 1 && @.a == 4)'::jsonpath; |
||||
jsonpath |
||||
---------------------------------- |
||||
$."g"?(@."a" == 1 && @."a" == 4) |
||||
(1 row) |
||||
|
||||
select '$.g ? (@.a == 1 || @.a == 4 && @.b == 7)'::jsonpath; |
||||
jsonpath |
||||
------------------------------------------------ |
||||
$."g"?(@."a" == 1 || @."a" == 4 && @."b" == 7) |
||||
(1 row) |
||||
|
||||
select '$.g ? (@.a == 1 || !(@.a == 4) && @.b == 7)'::jsonpath; |
||||
jsonpath |
||||
--------------------------------------------------- |
||||
$."g"?(@."a" == 1 || !(@."a" == 4) && @."b" == 7) |
||||
(1 row) |
||||
|
||||
select '$.g ? (@.a == 1 || !(@.x >= 123 || @.a == 4) && @.b == 7)'::jsonpath; |
||||
jsonpath |
||||
------------------------------------------------------------------- |
||||
$."g"?(@."a" == 1 || !(@."x" >= 123 || @."a" == 4) && @."b" == 7) |
||||
(1 row) |
||||
|
||||
select '$.g ? (@.x >= @[*]?(@.a > "abc"))'::jsonpath; |
||||
jsonpath |
||||
--------------------------------------- |
||||
$."g"?(@."x" >= @[*]?(@."a" > "abc")) |
||||
(1 row) |
||||
|
||||
select '$.g ? ((@.x >= 123 || @.a == 4) is unknown)'::jsonpath; |
||||
jsonpath |
||||
------------------------------------------------- |
||||
$."g"?((@."x" >= 123 || @."a" == 4) is unknown) |
||||
(1 row) |
||||
|
||||
select '$.g ? (exists (@.x))'::jsonpath; |
||||
jsonpath |
||||
------------------------ |
||||
$."g"?(exists (@."x")) |
||||
(1 row) |
||||
|
||||
select '$.g ? (exists (@.x ? (@ == 14)))'::jsonpath; |
||||
jsonpath |
||||
---------------------------------- |
||||
$."g"?(exists (@."x"?(@ == 14))) |
||||
(1 row) |
||||
|
||||
select '$.g ? ((@.x >= 123 || @.a == 4) && exists (@.x ? (@ == 14)))'::jsonpath; |
||||
jsonpath |
||||
------------------------------------------------------------------ |
||||
$."g"?((@."x" >= 123 || @."a" == 4) && exists (@."x"?(@ == 14))) |
||||
(1 row) |
||||
|
||||
select '$.g ? (+@.x >= +-(+@.a + 2))'::jsonpath; |
||||
jsonpath |
||||
------------------------------------ |
||||
$."g"?(+@."x" >= +(-(+@."a" + 2))) |
||||
(1 row) |
||||
|
||||
select '$a'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$"a" |
||||
(1 row) |
||||
|
||||
select '$a.b'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$"a"."b" |
||||
(1 row) |
||||
|
||||
select '$a[*]'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$"a"[*] |
||||
(1 row) |
||||
|
||||
select '$.g ? (@.zip == $zip)'::jsonpath; |
||||
jsonpath |
||||
--------------------------- |
||||
$."g"?(@."zip" == $"zip") |
||||
(1 row) |
||||
|
||||
select '$.a[1,2, 3 to 16]'::jsonpath; |
||||
jsonpath |
||||
-------------------- |
||||
$."a"[1,2,3 to 16] |
||||
(1 row) |
||||
|
||||
select '$.a[$a + 1, ($b[*]) to -($[0] * 2)]'::jsonpath; |
||||
jsonpath |
||||
---------------------------------------- |
||||
$."a"[$"a" + 1,$"b"[*] to -($[0] * 2)] |
||||
(1 row) |
||||
|
||||
select '$.a[$.a.size() - 3]'::jsonpath; |
||||
jsonpath |
||||
------------------------- |
||||
$."a"[$."a".size() - 3] |
||||
(1 row) |
||||
|
||||
select 'last'::jsonpath; |
||||
ERROR: LAST is allowed only in array subscripts |
||||
LINE 1: select 'last'::jsonpath; |
||||
^ |
||||
select '"last"'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
"last" |
||||
(1 row) |
||||
|
||||
select '$.last'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$."last" |
||||
(1 row) |
||||
|
||||
select '$ ? (last > 0)'::jsonpath; |
||||
ERROR: LAST is allowed only in array subscripts |
||||
LINE 1: select '$ ? (last > 0)'::jsonpath; |
||||
^ |
||||
select '$[last]'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$[last] |
||||
(1 row) |
||||
|
||||
select '$[$[0] ? (last > 0)]'::jsonpath; |
||||
jsonpath |
||||
-------------------- |
||||
$[$[0]?(last > 0)] |
||||
(1 row) |
||||
|
||||
select 'null.type()'::jsonpath; |
||||
jsonpath |
||||
------------- |
||||
null.type() |
||||
(1 row) |
||||
|
||||
select '1.type()'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
1.type() |
||||
(1 row) |
||||
|
||||
select '"aaa".type()'::jsonpath; |
||||
jsonpath |
||||
-------------- |
||||
"aaa".type() |
||||
(1 row) |
||||
|
||||
select 'true.type()'::jsonpath; |
||||
jsonpath |
||||
------------- |
||||
true.type() |
||||
(1 row) |
||||
|
||||
select '$.double().floor().ceiling().abs()'::jsonpath; |
||||
jsonpath |
||||
------------------------------------ |
||||
$.double().floor().ceiling().abs() |
||||
(1 row) |
||||
|
||||
select '$.keyvalue().key'::jsonpath; |
||||
jsonpath |
||||
-------------------- |
||||
$.keyvalue()."key" |
||||
(1 row) |
||||
|
||||
select '$ ? (@ starts with "abc")'::jsonpath; |
||||
jsonpath |
||||
------------------------- |
||||
$?(@ starts with "abc") |
||||
(1 row) |
||||
|
||||
select '$ ? (@ starts with $var)'::jsonpath; |
||||
jsonpath |
||||
-------------------------- |
||||
$?(@ starts with $"var") |
||||
(1 row) |
||||
|
||||
select '$ ? (@ like_regex "(invalid pattern")'::jsonpath; |
||||
ERROR: invalid regular expression: parentheses () not balanced |
||||
LINE 1: select '$ ? (@ like_regex "(invalid pattern")'::jsonpath; |
||||
^ |
||||
select '$ ? (@ like_regex "pattern")'::jsonpath; |
||||
jsonpath |
||||
---------------------------- |
||||
$?(@ like_regex "pattern") |
||||
(1 row) |
||||
|
||||
select '$ ? (@ like_regex "pattern" flag "")'::jsonpath; |
||||
jsonpath |
||||
---------------------------- |
||||
$?(@ like_regex "pattern") |
||||
(1 row) |
||||
|
||||
select '$ ? (@ like_regex "pattern" flag "i")'::jsonpath; |
||||
jsonpath |
||||
------------------------------------- |
||||
$?(@ like_regex "pattern" flag "i") |
||||
(1 row) |
||||
|
||||
select '$ ? (@ like_regex "pattern" flag "is")'::jsonpath; |
||||
jsonpath |
||||
-------------------------------------- |
||||
$?(@ like_regex "pattern" flag "is") |
||||
(1 row) |
||||
|
||||
select '$ ? (@ like_regex "pattern" flag "isim")'::jsonpath; |
||||
jsonpath |
||||
-------------------------------------- |
||||
$?(@ like_regex "pattern" flag "im") |
||||
(1 row) |
||||
|
||||
select '$ ? (@ like_regex "pattern" flag "xsms")'::jsonpath; |
||||
jsonpath |
||||
-------------------------------------- |
||||
$?(@ like_regex "pattern" flag "sx") |
||||
(1 row) |
||||
|
||||
select '$ ? (@ like_regex "pattern" flag "a")'::jsonpath; |
||||
ERROR: bad jsonpath representation |
||||
LINE 1: select '$ ? (@ like_regex "pattern" flag "a")'::jsonpath; |
||||
^ |
||||
DETAIL: unrecognized flag of LIKE_REGEX predicate at or near """ |
||||
select '$ < 1'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
($ < 1) |
||||
(1 row) |
||||
|
||||
select '($ < 1) || $.a.b <= $x'::jsonpath; |
||||
jsonpath |
||||
------------------------------ |
||||
($ < 1 || $."a"."b" <= $"x") |
||||
(1 row) |
||||
|
||||
select '@ + 1'::jsonpath; |
||||
ERROR: @ is not allowed in root expressions |
||||
LINE 1: select '@ + 1'::jsonpath; |
||||
^ |
||||
select '($).a.b'::jsonpath; |
||||
jsonpath |
||||
----------- |
||||
$."a"."b" |
||||
(1 row) |
||||
|
||||
select '($.a.b).c.d'::jsonpath; |
||||
jsonpath |
||||
------------------- |
||||
$."a"."b"."c"."d" |
||||
(1 row) |
||||
|
||||
select '($.a.b + -$.x.y).c.d'::jsonpath; |
||||
jsonpath |
||||
---------------------------------- |
||||
($."a"."b" + -$."x"."y")."c"."d" |
||||
(1 row) |
||||
|
||||
select '(-+$.a.b).c.d'::jsonpath; |
||||
jsonpath |
||||
------------------------- |
||||
(-(+$."a"."b"))."c"."d" |
||||
(1 row) |
||||
|
||||
select '1 + ($.a.b + 2).c.d'::jsonpath; |
||||
jsonpath |
||||
------------------------------- |
||||
(1 + ($."a"."b" + 2)."c"."d") |
||||
(1 row) |
||||
|
||||
select '1 + ($.a.b > 2).c.d'::jsonpath; |
||||
jsonpath |
||||
------------------------------- |
||||
(1 + ($."a"."b" > 2)."c"."d") |
||||
(1 row) |
||||
|
||||
select '($)'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$ |
||||
(1 row) |
||||
|
||||
select '(($))'::jsonpath; |
||||
jsonpath |
||||
---------- |
||||
$ |
||||
(1 row) |
||||
|
||||
select '((($ + 1)).a + ((2)).b ? ((((@ > 1)) || (exists(@.c)))))'::jsonpath; |
||||
jsonpath |
||||
------------------------------------------------- |
||||
(($ + 1)."a" + 2."b"?(@ > 1 || exists (@."c"))) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$?(@."a" < -1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < .1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 0.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -.1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < -0.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +.1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 0.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 0.1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 0.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -0.1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < -0.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +0.1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 0.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 10.1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < 10.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -10.1)'::jsonpath; |
||||
jsonpath |
||||
------------------- |
||||
$?(@."a" < -10.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +10.1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < 10.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 1e1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$?(@."a" < 10) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -1e1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < -10) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +1e1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$?(@."a" < 10) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < .1e1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -.1e1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$?(@."a" < -1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +.1e1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 0.1e1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -0.1e1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$?(@."a" < -1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +0.1e1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 10.1e1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 101) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -10.1e1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < -101) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +10.1e1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 101) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 1e-1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 0.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < -0.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +1e-1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 0.1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < .1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < 0.01) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -.1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------- |
||||
$?(@."a" < -0.01) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +.1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < 0.01) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 0.1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < 0.01) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -0.1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------- |
||||
$?(@."a" < -0.01) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +0.1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < 0.01) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 10.1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < 1.01) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -10.1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------- |
||||
$?(@."a" < -1.01) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +10.1e-1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < 1.01) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 1e+1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$?(@."a" < 10) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -1e+1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < -10) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +1e+1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$?(@."a" < 10) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < .1e+1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -.1e+1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$?(@."a" < -1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +.1e+1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 0.1e+1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -0.1e+1)'::jsonpath; |
||||
jsonpath |
||||
---------------- |
||||
$?(@."a" < -1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +0.1e+1)'::jsonpath; |
||||
jsonpath |
||||
--------------- |
||||
$?(@."a" < 1) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < 10.1e+1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 101) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < -10.1e+1)'::jsonpath; |
||||
jsonpath |
||||
------------------ |
||||
$?(@."a" < -101) |
||||
(1 row) |
||||
|
||||
select '$ ? (@.a < +10.1e+1)'::jsonpath; |
||||
jsonpath |
||||
----------------- |
||||
$?(@."a" < 101) |
||||
(1 row) |
||||
|
@ -0,0 +1,369 @@ |
||||
select jsonb '{"a": 12}' @? '$'; |
||||
select jsonb '{"a": 12}' @? '1'; |
||||
select jsonb '{"a": 12}' @? '$.a.b'; |
||||
select jsonb '{"a": 12}' @? '$.b'; |
||||
select jsonb '{"a": 12}' @? '$.a + 2'; |
||||
select jsonb '{"a": 12}' @? '$.b + 2'; |
||||
select jsonb '{"a": {"a": 12}}' @? '$.a.a'; |
||||
select jsonb '{"a": {"a": 12}}' @? '$.*.a'; |
||||
select jsonb '{"b": {"a": 12}}' @? '$.*.a'; |
||||
select jsonb '{"b": {"a": 12}}' @? '$.*.b'; |
||||
select jsonb '{"b": {"a": 12}}' @? 'strict $.*.b'; |
||||
select jsonb '{}' @? '$.*'; |
||||
select jsonb '{"a": 1}' @? '$.*'; |
||||
select jsonb '{"a": {"b": 1}}' @? 'lax $.**{1}'; |
||||
select jsonb '{"a": {"b": 1}}' @? 'lax $.**{2}'; |
||||
select jsonb '{"a": {"b": 1}}' @? 'lax $.**{3}'; |
||||
select jsonb '[]' @? '$[*]'; |
||||
select jsonb '[1]' @? '$[*]'; |
||||
select jsonb '[1]' @? '$[1]'; |
||||
select jsonb '[1]' @? 'strict $[1]'; |
||||
select jsonb_path_query('[1]', 'strict $[1]'); |
||||
select jsonb_path_query('[1]', 'strict $[1]', silent => true); |
||||
select jsonb '[1]' @? 'lax $[10000000000000000]'; |
||||
select jsonb '[1]' @? 'strict $[10000000000000000]'; |
||||
select jsonb_path_query('[1]', 'lax $[10000000000000000]'); |
||||
select jsonb_path_query('[1]', 'strict $[10000000000000000]'); |
||||
select jsonb '[1]' @? '$[0]'; |
||||
select jsonb '[1]' @? '$[0.3]'; |
||||
select jsonb '[1]' @? '$[0.5]'; |
||||
select jsonb '[1]' @? '$[0.9]'; |
||||
select jsonb '[1]' @? '$[1.2]'; |
||||
select jsonb '[1]' @? 'strict $[1.2]'; |
||||
select jsonb '{"a": [1,2,3], "b": [3,4,5]}' @? '$ ? (@.a[*] > @.b[*])'; |
||||
select jsonb '{"a": [1,2,3], "b": [3,4,5]}' @? '$ ? (@.a[*] >= @.b[*])'; |
||||
select jsonb '{"a": [1,2,3], "b": [3,4,"5"]}' @? '$ ? (@.a[*] >= @.b[*])'; |
||||
select jsonb '{"a": [1,2,3], "b": [3,4,"5"]}' @? 'strict $ ? (@.a[*] >= @.b[*])'; |
||||
select jsonb '{"a": [1,2,3], "b": [3,4,null]}' @? '$ ? (@.a[*] >= @.b[*])'; |
||||
select jsonb '1' @? '$ ? ((@ == "1") is unknown)'; |
||||
select jsonb '1' @? '$ ? ((@ == 1) is unknown)'; |
||||
select jsonb '[{"a": 1}, {"a": 2}]' @? '$[0 to 1] ? (@.a > 1)'; |
||||
|
||||
select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', silent => false); |
||||
select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', silent => true); |
||||
select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', silent => false); |
||||
select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', silent => true); |
||||
|
||||
select jsonb_path_query('1', 'lax $.a'); |
||||
select jsonb_path_query('1', 'strict $.a'); |
||||
select jsonb_path_query('1', 'strict $.*'); |
||||
select jsonb_path_query('1', 'strict $.a', silent => true); |
||||
select jsonb_path_query('1', 'strict $.*', silent => true); |
||||
select jsonb_path_query('[]', 'lax $.a'); |
||||
select jsonb_path_query('[]', 'strict $.a'); |
||||
select jsonb_path_query('[]', 'strict $.a', silent => true); |
||||
select jsonb_path_query('{}', 'lax $.a'); |
||||
select jsonb_path_query('{}', 'strict $.a'); |
||||
select jsonb_path_query('{}', 'strict $.a', silent => true); |
||||
|
||||
select jsonb_path_query('1', 'strict $[1]'); |
||||
select jsonb_path_query('1', 'strict $[*]'); |
||||
select jsonb_path_query('[]', 'strict $[1]'); |
||||
select jsonb_path_query('[]', 'strict $["a"]'); |
||||
select jsonb_path_query('1', 'strict $[1]', silent => true); |
||||
select jsonb_path_query('1', 'strict $[*]', silent => true); |
||||
select jsonb_path_query('[]', 'strict $[1]', silent => true); |
||||
select jsonb_path_query('[]', 'strict $["a"]', silent => true); |
||||
|
||||
select jsonb_path_query('{"a": 12, "b": {"a": 13}}', '$.a'); |
||||
select jsonb_path_query('{"a": 12, "b": {"a": 13}}', '$.b'); |
||||
select jsonb_path_query('{"a": 12, "b": {"a": 13}}', '$.*'); |
||||
select jsonb_path_query('{"a": 12, "b": {"a": 13}}', 'lax $.*.a'); |
||||
select jsonb_path_query('[12, {"a": 13}, {"b": 14}]', 'lax $[*].a'); |
||||
select jsonb_path_query('[12, {"a": 13}, {"b": 14}]', 'lax $[*].*'); |
||||
select jsonb_path_query('[12, {"a": 13}, {"b": 14}]', 'lax $[0].a'); |
||||
select jsonb_path_query('[12, {"a": 13}, {"b": 14}]', 'lax $[1].a'); |
||||
select jsonb_path_query('[12, {"a": 13}, {"b": 14}]', 'lax $[2].a'); |
||||
select jsonb_path_query('[12, {"a": 13}, {"b": 14}]', 'lax $[0,1].a'); |
||||
select jsonb_path_query('[12, {"a": 13}, {"b": 14}]', 'lax $[0 to 10].a'); |
||||
select jsonb_path_query('[12, {"a": 13}, {"b": 14}]', 'lax $[0 to 10 / 0].a'); |
||||
select jsonb_path_query('[12, {"a": 13}, {"b": 14}, "ccc", true]', '$[2.5 - 1 to $.size() - 2]'); |
||||
select jsonb_path_query('1', 'lax $[0]'); |
||||
select jsonb_path_query('1', 'lax $[*]'); |
||||
select jsonb_path_query('[1]', 'lax $[0]'); |
||||
select jsonb_path_query('[1]', 'lax $[*]'); |
||||
select jsonb_path_query('[1,2,3]', 'lax $[*]'); |
||||
select jsonb_path_query('[1,2,3]', 'strict $[*].a'); |
||||
select jsonb_path_query('[1,2,3]', 'strict $[*].a', silent => true); |
||||
select jsonb_path_query('[]', '$[last]'); |
||||
select jsonb_path_query('[]', '$[last ? (exists(last))]'); |
||||
select jsonb_path_query('[]', 'strict $[last]'); |
||||
select jsonb_path_query('[]', 'strict $[last]', silent => true); |
||||
select jsonb_path_query('[1]', '$[last]'); |
||||
select jsonb_path_query('[1,2,3]', '$[last]'); |
||||
select jsonb_path_query('[1,2,3]', '$[last - 1]'); |
||||
select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "number")]'); |
||||
select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "string")]'); |
||||
select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "string")]', silent => true); |
||||
|
||||
select * from jsonb_path_query('{"a": 10}', '$'); |
||||
select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)'); |
||||
select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '1'); |
||||
select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '[{"value" : 13}]'); |
||||
select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '{"value" : 13}'); |
||||
select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '{"value" : 8}'); |
||||
select * from jsonb_path_query('{"a": 10}', '$.a ? (@ < $value)', '{"value" : 13}'); |
||||
select * from jsonb_path_query('[10,11,12,13,14,15]', '$[*] ? (@ < $value)', '{"value" : 13}'); |
||||
select * from jsonb_path_query('[10,11,12,13,14,15]', '$[0,1] ? (@ < $x.value)', '{"x": {"value" : 13}}'); |
||||
select * from jsonb_path_query('[10,11,12,13,14,15]', '$[0 to 2] ? (@ < $value)', '{"value" : 15}'); |
||||
select * from jsonb_path_query('[1,"1",2,"2",null]', '$[*] ? (@ == "1")'); |
||||
select * from jsonb_path_query('[1,"1",2,"2",null]', '$[*] ? (@ == $value)', '{"value" : "1"}'); |
||||
select * from jsonb_path_query('[1,"1",2,"2",null]', '$[*] ? (@ == $value)', '{"value" : null}'); |
||||
select * from jsonb_path_query('[1, "2", null]', '$[*] ? (@ != null)'); |
||||
select * from jsonb_path_query('[1, "2", null]', '$[*] ? (@ == null)'); |
||||
select * from jsonb_path_query('{}', '$ ? (@ == @)'); |
||||
select * from jsonb_path_query('[]', 'strict $ ? (@ == @)'); |
||||
|
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{0}'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{0 to last}'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{1}'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{1 to last}'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{2}'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{2 to last}'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{3 to last}'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{last}'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{0}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{1}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{0 to last}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{1 to last}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{1 to 2}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{0}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{1}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{0 to last}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{1 to last}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{1 to 2}.b ? (@ > 0)'); |
||||
select jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{2 to 3}.b ? (@ > 0)'); |
||||
|
||||
select jsonb '{"a": {"b": 1}}' @? '$.**.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"b": 1}}' @? '$.**{0}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"b": 1}}' @? '$.**{1}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"b": 1}}' @? '$.**{0 to last}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"b": 1}}' @? '$.**{1 to last}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"b": 1}}' @? '$.**{1 to 2}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"c": {"b": 1}}}' @? '$.**.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"c": {"b": 1}}}' @? '$.**{0}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"c": {"b": 1}}}' @? '$.**{1}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"c": {"b": 1}}}' @? '$.**{0 to last}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"c": {"b": 1}}}' @? '$.**{1 to last}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"c": {"b": 1}}}' @? '$.**{1 to 2}.b ? ( @ > 0)'; |
||||
select jsonb '{"a": {"c": {"b": 1}}}' @? '$.**{2 to 3}.b ? ( @ > 0)'; |
||||
|
||||
select jsonb_path_query('{"g": {"x": 2}}', '$.g ? (exists (@.x))'); |
||||
select jsonb_path_query('{"g": {"x": 2}}', '$.g ? (exists (@.y))'); |
||||
select jsonb_path_query('{"g": {"x": 2}}', '$.g ? (exists (@.x ? (@ >= 2) ))'); |
||||
select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'lax $.g ? (exists (@.x))'); |
||||
select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'lax $.g ? (exists (@.x + "3"))'); |
||||
select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'lax $.g ? ((exists (@.x + "3")) is unknown)'); |
||||
select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'strict $.g[*] ? (exists (@.x))'); |
||||
select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'strict $.g[*] ? ((exists (@.x)) is unknown)'); |
||||
select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'strict $.g ? (exists (@[*].x))'); |
||||
select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'strict $.g ? ((exists (@[*].x)) is unknown)'); |
||||
|
||||
--test ternary logic |
||||
select |
||||
x, y, |
||||
jsonb_path_query( |
||||
'[true, false, null]', |
||||
'$[*] ? (@ == true && ($x == true && $y == true) || |
||||
@ == false && !($x == true && $y == true) || |
||||
@ == null && ($x == true && $y == true) is unknown)', |
||||
jsonb_build_object('x', x, 'y', y) |
||||
) as "x && y" |
||||
from |
||||
(values (jsonb 'true'), ('false'), ('"null"')) x(x), |
||||
(values (jsonb 'true'), ('false'), ('"null"')) y(y); |
||||
|
||||
select |
||||
x, y, |
||||
jsonb_path_query( |
||||
'[true, false, null]', |
||||
'$[*] ? (@ == true && ($x == true || $y == true) || |
||||
@ == false && !($x == true || $y == true) || |
||||
@ == null && ($x == true || $y == true) is unknown)', |
||||
jsonb_build_object('x', x, 'y', y) |
||||
) as "x || y" |
||||
from |
||||
(values (jsonb 'true'), ('false'), ('"null"')) x(x), |
||||
(values (jsonb 'true'), ('false'), ('"null"')) y(y); |
||||
|
||||
select jsonb '{"a": 1, "b":1}' @? '$ ? (@.a == @.b)'; |
||||
select jsonb '{"c": {"a": 1, "b":1}}' @? '$ ? (@.a == @.b)'; |
||||
select jsonb '{"c": {"a": 1, "b":1}}' @? '$.c ? (@.a == @.b)'; |
||||
select jsonb '{"c": {"a": 1, "b":1}}' @? '$.c ? ($.c.a == @.b)'; |
||||
select jsonb '{"c": {"a": 1, "b":1}}' @? '$.* ? (@.a == @.b)'; |
||||
select jsonb '{"a": 1, "b":1}' @? '$.** ? (@.a == @.b)'; |
||||
select jsonb '{"c": {"a": 1, "b":1}}' @? '$.** ? (@.a == @.b)'; |
||||
|
||||
select jsonb_path_query('{"c": {"a": 2, "b":1}}', '$.** ? (@.a == 1 + 1)'); |
||||
select jsonb_path_query('{"c": {"a": 2, "b":1}}', '$.** ? (@.a == (1 + 1))'); |
||||
select jsonb_path_query('{"c": {"a": 2, "b":1}}', '$.** ? (@.a == @.b + 1)'); |
||||
select jsonb_path_query('{"c": {"a": 2, "b":1}}', '$.** ? (@.a == (@.b + 1))'); |
||||
select jsonb '{"c": {"a": -1, "b":1}}' @? '$.** ? (@.a == - 1)'; |
||||
select jsonb '{"c": {"a": -1, "b":1}}' @? '$.** ? (@.a == -1)'; |
||||
select jsonb '{"c": {"a": -1, "b":1}}' @? '$.** ? (@.a == -@.b)'; |
||||
select jsonb '{"c": {"a": -1, "b":1}}' @? '$.** ? (@.a == - @.b)'; |
||||
select jsonb '{"c": {"a": 0, "b":1}}' @? '$.** ? (@.a == 1 - @.b)'; |
||||
select jsonb '{"c": {"a": 2, "b":1}}' @? '$.** ? (@.a == 1 - - @.b)'; |
||||
select jsonb '{"c": {"a": 0, "b":1}}' @? '$.** ? (@.a == 1 - +@.b)'; |
||||
select jsonb '[1,2,3]' @? '$ ? (+@[*] > +2)'; |
||||
select jsonb '[1,2,3]' @? '$ ? (+@[*] > +3)'; |
||||
select jsonb '[1,2,3]' @? '$ ? (-@[*] < -2)'; |
||||
select jsonb '[1,2,3]' @? '$ ? (-@[*] < -3)'; |
||||
select jsonb '1' @? '$ ? ($ > 0)'; |
||||
|
||||
-- arithmetic errors |
||||
select jsonb_path_query('[1,2,0,3]', '$[*] ? (2 / @ > 0)'); |
||||
select jsonb_path_query('[1,2,0,3]', '$[*] ? ((2 / @ > 0) is unknown)'); |
||||
select jsonb_path_query('0', '1 / $'); |
||||
select jsonb_path_query('0', '1 / $ + 2'); |
||||
select jsonb_path_query('0', '-(3 + 1 % $)'); |
||||
select jsonb_path_query('1', '$ + "2"'); |
||||
select jsonb_path_query('[1, 2]', '3 * $'); |
||||
select jsonb_path_query('"a"', '-$'); |
||||
select jsonb_path_query('[1,"2",3]', '+$'); |
||||
select jsonb_path_query('1', '$ + "2"', silent => true); |
||||
select jsonb_path_query('[1, 2]', '3 * $', silent => true); |
||||
select jsonb_path_query('"a"', '-$', silent => true); |
||||
select jsonb_path_query('[1,"2",3]', '+$', silent => true); |
||||
select jsonb '["1",2,0,3]' @? '-$[*]'; |
||||
select jsonb '[1,"2",0,3]' @? '-$[*]'; |
||||
select jsonb '["1",2,0,3]' @? 'strict -$[*]'; |
||||
select jsonb '[1,"2",0,3]' @? 'strict -$[*]'; |
||||
|
||||
-- unwrapping of operator arguments in lax mode |
||||
select jsonb_path_query('{"a": [2]}', 'lax $.a * 3'); |
||||
select jsonb_path_query('{"a": [2]}', 'lax $.a + 3'); |
||||
select jsonb_path_query('{"a": [2, 3, 4]}', 'lax -$.a'); |
||||
-- should fail |
||||
select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3'); |
||||
select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3', silent => true); |
||||
|
||||
-- extension: boolean expressions |
||||
select jsonb_path_query('2', '$ > 1'); |
||||
select jsonb_path_query('2', '$ <= 1'); |
||||
select jsonb_path_query('2', '$ == "2"'); |
||||
select jsonb '2' @? '$ == "2"'; |
||||
|
||||
select jsonb '2' @@ '$ > 1'; |
||||
select jsonb '2' @@ '$ <= 1'; |
||||
select jsonb '2' @@ '$ == "2"'; |
||||
select jsonb '2' @@ '1'; |
||||
select jsonb '{}' @@ '$'; |
||||
select jsonb '[]' @@ '$'; |
||||
select jsonb '[1,2,3]' @@ '$[*]'; |
||||
select jsonb '[]' @@ '$[*]'; |
||||
select jsonb_path_match('[[1, true], [2, false]]', 'strict $[*] ? (@[0] > $x) [1]', '{"x": 1}'); |
||||
select jsonb_path_match('[[1, true], [2, false]]', 'strict $[*] ? (@[0] < $x) [1]', '{"x": 2}'); |
||||
|
||||
select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'lax exists($[*].a)', silent => false); |
||||
select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'lax exists($[*].a)', silent => true); |
||||
select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'strict exists($[*].a)', silent => false); |
||||
select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'strict exists($[*].a)', silent => true); |
||||
|
||||
|
||||
select jsonb_path_query('[null,1,true,"a",[],{}]', '$.type()'); |
||||
select jsonb_path_query('[null,1,true,"a",[],{}]', 'lax $.type()'); |
||||
select jsonb_path_query('[null,1,true,"a",[],{}]', '$[*].type()'); |
||||
select jsonb_path_query('null', 'null.type()'); |
||||
select jsonb_path_query('null', 'true.type()'); |
||||
select jsonb_path_query('null', '123.type()'); |
||||
select jsonb_path_query('null', '"123".type()'); |
||||
|
||||
select jsonb_path_query('{"a": 2}', '($.a - 5).abs() + 10'); |
||||
select jsonb_path_query('{"a": 2.5}', '-($.a * $.a).floor() % 4.3'); |
||||
select jsonb_path_query('[1, 2, 3]', '($[*] > 2) ? (@ == true)'); |
||||
select jsonb_path_query('[1, 2, 3]', '($[*] > 3).type()'); |
||||
select jsonb_path_query('[1, 2, 3]', '($[*].a > 3).type()'); |
||||
select jsonb_path_query('[1, 2, 3]', 'strict ($[*].a > 3).type()'); |
||||
|
||||
select jsonb_path_query('[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'strict $[*].size()'); |
||||
select jsonb_path_query('[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'strict $[*].size()', silent => true); |
||||
select jsonb_path_query('[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'lax $[*].size()'); |
||||
|
||||
select jsonb_path_query('[0, 1, -2, -3.4, 5.6]', '$[*].abs()'); |
||||
select jsonb_path_query('[0, 1, -2, -3.4, 5.6]', '$[*].floor()'); |
||||
select jsonb_path_query('[0, 1, -2, -3.4, 5.6]', '$[*].ceiling()'); |
||||
select jsonb_path_query('[0, 1, -2, -3.4, 5.6]', '$[*].ceiling().abs()'); |
||||
select jsonb_path_query('[0, 1, -2, -3.4, 5.6]', '$[*].ceiling().abs().type()'); |
||||
|
||||
select jsonb_path_query('[{},1]', '$[*].keyvalue()'); |
||||
select jsonb_path_query('[{},1]', '$[*].keyvalue()', silent => true); |
||||
select jsonb_path_query('{}', '$.keyvalue()'); |
||||
select jsonb_path_query('{"a": 1, "b": [1, 2], "c": {"a": "bbb"}}', '$.keyvalue()'); |
||||
select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', '$[*].keyvalue()'); |
||||
select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'strict $.keyvalue()'); |
||||
select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'lax $.keyvalue()'); |
||||
select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'strict $.keyvalue().a'); |
||||
select jsonb '{"a": 1, "b": [1, 2]}' @? 'lax $.keyvalue()'; |
||||
select jsonb '{"a": 1, "b": [1, 2]}' @? 'lax $.keyvalue().key'; |
||||
|
||||
select jsonb_path_query('null', '$.double()'); |
||||
select jsonb_path_query('true', '$.double()'); |
||||
select jsonb_path_query('null', '$.double()', silent => true); |
||||
select jsonb_path_query('true', '$.double()', silent => true); |
||||
select jsonb_path_query('[]', '$.double()'); |
||||
select jsonb_path_query('[]', 'strict $.double()'); |
||||
select jsonb_path_query('{}', '$.double()'); |
||||
select jsonb_path_query('[]', 'strict $.double()', silent => true); |
||||
select jsonb_path_query('{}', '$.double()', silent => true); |
||||
select jsonb_path_query('1.23', '$.double()'); |
||||
select jsonb_path_query('"1.23"', '$.double()'); |
||||
select jsonb_path_query('"1.23aaa"', '$.double()'); |
||||
select jsonb_path_query('"nan"', '$.double()'); |
||||
select jsonb_path_query('"NaN"', '$.double()'); |
||||
select jsonb_path_query('"inf"', '$.double()'); |
||||
select jsonb_path_query('"-inf"', '$.double()'); |
||||
select jsonb_path_query('"inf"', '$.double()', silent => true); |
||||
select jsonb_path_query('"-inf"', '$.double()', silent => true); |
||||
|
||||
select jsonb_path_query('{}', '$.abs()'); |
||||
select jsonb_path_query('true', '$.floor()'); |
||||
select jsonb_path_query('"1.2"', '$.ceiling()'); |
||||
select jsonb_path_query('{}', '$.abs()', silent => true); |
||||
select jsonb_path_query('true', '$.floor()', silent => true); |
||||
select jsonb_path_query('"1.2"', '$.ceiling()', silent => true); |
||||
|
||||
select jsonb_path_query('["", "a", "abc", "abcabc"]', '$[*] ? (@ starts with "abc")'); |
||||
select jsonb_path_query('["", "a", "abc", "abcabc"]', 'strict $ ? (@[*] starts with "abc")'); |
||||
select jsonb_path_query('["", "a", "abd", "abdabc"]', 'strict $ ? (@[*] starts with "abc")'); |
||||
select jsonb_path_query('["abc", "abcabc", null, 1]', 'strict $ ? (@[*] starts with "abc")'); |
||||
select jsonb_path_query('["abc", "abcabc", null, 1]', 'strict $ ? ((@[*] starts with "abc") is unknown)'); |
||||
select jsonb_path_query('[[null, 1, "abc", "abcabc"]]', 'lax $ ? (@[*] starts with "abc")'); |
||||
select jsonb_path_query('[[null, 1, "abd", "abdabc"]]', 'lax $ ? ((@[*] starts with "abc") is unknown)'); |
||||
select jsonb_path_query('[null, 1, "abd", "abdabc"]', 'lax $[*] ? ((@ starts with "abc") is unknown)'); |
||||
|
||||
select jsonb_path_query('[null, 1, "abc", "abd", "aBdC", "abdacb", "adc\nabc", "babc"]', 'lax $[*] ? (@ like_regex "^ab.*c")'); |
||||
select jsonb_path_query('[null, 1, "abc", "abd", "aBdC", "abdacb", "adc\nabc", "babc"]', 'lax $[*] ? (@ like_regex "^a b.* c " flag "ix")'); |
||||
select jsonb_path_query('[null, 1, "abc", "abd", "aBdC", "abdacb", "adc\nabc", "babc"]', 'lax $[*] ? (@ like_regex "^ab.*c" flag "m")'); |
||||
select jsonb_path_query('[null, 1, "abc", "abd", "aBdC", "abdacb", "adc\nabc", "babc"]', 'lax $[*] ? (@ like_regex "^ab.*c" flag "s")'); |
||||
|
||||
-- jsonpath operators |
||||
|
||||
SELECT jsonb_path_query('[{"a": 1}, {"a": 2}]', '$[*]'); |
||||
SELECT jsonb_path_query('[{"a": 1}, {"a": 2}]', '$[*] ? (@.a > 10)'); |
||||
|
||||
SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a'); |
||||
SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}]', '$[*].a'); |
||||
SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}]', '$[*].a ? (@ == 1)'); |
||||
SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}]', '$[*].a ? (@ > 10)'); |
||||
SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', vars => '{"min": 1, "max": 4}'); |
||||
SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', vars => '{"min": 3, "max": 4}'); |
||||
|
||||
SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a'); |
||||
SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a', silent => true); |
||||
SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}]', '$[*].a'); |
||||
SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}]', '$[*].a ? (@ == 1)'); |
||||
SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}]', '$[*].a ? (@ > 10)'); |
||||
SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', vars => '{"min": 1, "max": 4}'); |
||||
SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', vars => '{"min": 3, "max": 4}'); |
||||
|
||||
SELECT jsonb '[{"a": 1}, {"a": 2}]' @? '$[*].a ? (@ > 1)'; |
||||
SELECT jsonb '[{"a": 1}, {"a": 2}]' @? '$[*] ? (@.a > 2)'; |
||||
SELECT jsonb_path_exists('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*] ? (@.a > $min && @.a < $max)', vars => '{"min": 1, "max": 4}'); |
||||
SELECT jsonb_path_exists('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*] ? (@.a > $min && @.a < $max)', vars => '{"min": 3, "max": 4}'); |
||||
|
||||
SELECT jsonb '[{"a": 1}, {"a": 2}]' @@ '$[*].a > 1'; |
||||
SELECT jsonb '[{"a": 1}, {"a": 2}]' @@ '$[*].a > 2'; |
@ -0,0 +1,147 @@ |
||||
--jsonpath io |
||||
|
||||
select ''::jsonpath; |
||||
select '$'::jsonpath; |
||||
select 'strict $'::jsonpath; |
||||
select 'lax $'::jsonpath; |
||||
select '$.a'::jsonpath; |
||||
select '$.a.v'::jsonpath; |
||||
select '$.a.*'::jsonpath; |
||||
select '$.*[*]'::jsonpath; |
||||
select '$.a[*]'::jsonpath; |
||||
select '$.a[*][*]'::jsonpath; |
||||
select '$[*]'::jsonpath; |
||||
select '$[0]'::jsonpath; |
||||
select '$[*][0]'::jsonpath; |
||||
select '$[*].a'::jsonpath; |
||||
select '$[*][0].a.b'::jsonpath; |
||||
select '$.a.**.b'::jsonpath; |
||||
select '$.a.**{2}.b'::jsonpath; |
||||
select '$.a.**{2 to 2}.b'::jsonpath; |
||||
select '$.a.**{2 to 5}.b'::jsonpath; |
||||
select '$.a.**{0 to 5}.b'::jsonpath; |
||||
select '$.a.**{5 to last}.b'::jsonpath; |
||||
select '$.a.**{last}.b'::jsonpath; |
||||
select '$.a.**{last to 5}.b'::jsonpath; |
||||
select '$+1'::jsonpath; |
||||
select '$-1'::jsonpath; |
||||
select '$--+1'::jsonpath; |
||||
select '$.a/+-1'::jsonpath; |
||||
select '1 * 2 + 4 % -3 != false'::jsonpath; |
||||
|
||||
select '"\b\f\r\n\t\v\"\''\\"'::jsonpath; |
||||
select '''\b\f\r\n\t\v\"\''\\'''::jsonpath; |
||||
select '"\x50\u0067\u{53}\u{051}\u{00004C}"'::jsonpath; |
||||
select '''\x50\u0067\u{53}\u{051}\u{00004C}'''::jsonpath; |
||||
select '$.foo\x50\u0067\u{53}\u{051}\u{00004C}\t\"bar'::jsonpath; |
||||
|
||||
select '$.g ? ($.a == 1)'::jsonpath; |
||||
select '$.g ? (@ == 1)'::jsonpath; |
||||
select '$.g ? (@.a == 1)'::jsonpath; |
||||
select '$.g ? (@.a == 1 || @.a == 4)'::jsonpath; |
||||
select '$.g ? (@.a == 1 && @.a == 4)'::jsonpath; |
||||
select '$.g ? (@.a == 1 || @.a == 4 && @.b == 7)'::jsonpath; |
||||
select '$.g ? (@.a == 1 || !(@.a == 4) && @.b == 7)'::jsonpath; |
||||
select '$.g ? (@.a == 1 || !(@.x >= 123 || @.a == 4) && @.b == 7)'::jsonpath; |
||||
select '$.g ? (@.x >= @[*]?(@.a > "abc"))'::jsonpath; |
||||
select '$.g ? ((@.x >= 123 || @.a == 4) is unknown)'::jsonpath; |
||||
select '$.g ? (exists (@.x))'::jsonpath; |
||||
select '$.g ? (exists (@.x ? (@ == 14)))'::jsonpath; |
||||
select '$.g ? ((@.x >= 123 || @.a == 4) && exists (@.x ? (@ == 14)))'::jsonpath; |
||||
select '$.g ? (+@.x >= +-(+@.a + 2))'::jsonpath; |
||||
|
||||
select '$a'::jsonpath; |
||||
select '$a.b'::jsonpath; |
||||
select '$a[*]'::jsonpath; |
||||
select '$.g ? (@.zip == $zip)'::jsonpath; |
||||
select '$.a[1,2, 3 to 16]'::jsonpath; |
||||
select '$.a[$a + 1, ($b[*]) to -($[0] * 2)]'::jsonpath; |
||||
select '$.a[$.a.size() - 3]'::jsonpath; |
||||
select 'last'::jsonpath; |
||||
select '"last"'::jsonpath; |
||||
select '$.last'::jsonpath; |
||||
select '$ ? (last > 0)'::jsonpath; |
||||
select '$[last]'::jsonpath; |
||||
select '$[$[0] ? (last > 0)]'::jsonpath; |
||||
|
||||
select 'null.type()'::jsonpath; |
||||
select '1.type()'::jsonpath; |
||||
select '"aaa".type()'::jsonpath; |
||||
select 'true.type()'::jsonpath; |
||||
select '$.double().floor().ceiling().abs()'::jsonpath; |
||||
select '$.keyvalue().key'::jsonpath; |
||||
|
||||
select '$ ? (@ starts with "abc")'::jsonpath; |
||||
select '$ ? (@ starts with $var)'::jsonpath; |
||||
|
||||
select '$ ? (@ like_regex "(invalid pattern")'::jsonpath; |
||||
select '$ ? (@ like_regex "pattern")'::jsonpath; |
||||
select '$ ? (@ like_regex "pattern" flag "")'::jsonpath; |
||||
select '$ ? (@ like_regex "pattern" flag "i")'::jsonpath; |
||||
select '$ ? (@ like_regex "pattern" flag "is")'::jsonpath; |
||||
select '$ ? (@ like_regex "pattern" flag "isim")'::jsonpath; |
||||
select '$ ? (@ like_regex "pattern" flag "xsms")'::jsonpath; |
||||
select '$ ? (@ like_regex "pattern" flag "a")'::jsonpath; |
||||
|
||||
select '$ < 1'::jsonpath; |
||||
select '($ < 1) || $.a.b <= $x'::jsonpath; |
||||
select '@ + 1'::jsonpath; |
||||
|
||||
select '($).a.b'::jsonpath; |
||||
select '($.a.b).c.d'::jsonpath; |
||||
select '($.a.b + -$.x.y).c.d'::jsonpath; |
||||
select '(-+$.a.b).c.d'::jsonpath; |
||||
select '1 + ($.a.b + 2).c.d'::jsonpath; |
||||
select '1 + ($.a.b > 2).c.d'::jsonpath; |
||||
select '($)'::jsonpath; |
||||
select '(($))'::jsonpath; |
||||
select '((($ + 1)).a + ((2)).b ? ((((@ > 1)) || (exists(@.c)))))'::jsonpath; |
||||
|
||||
select '$ ? (@.a < 1)'::jsonpath; |
||||
select '$ ? (@.a < -1)'::jsonpath; |
||||
select '$ ? (@.a < +1)'::jsonpath; |
||||
select '$ ? (@.a < .1)'::jsonpath; |
||||
select '$ ? (@.a < -.1)'::jsonpath; |
||||
select '$ ? (@.a < +.1)'::jsonpath; |
||||
select '$ ? (@.a < 0.1)'::jsonpath; |
||||
select '$ ? (@.a < -0.1)'::jsonpath; |
||||
select '$ ? (@.a < +0.1)'::jsonpath; |
||||
select '$ ? (@.a < 10.1)'::jsonpath; |
||||
select '$ ? (@.a < -10.1)'::jsonpath; |
||||
select '$ ? (@.a < +10.1)'::jsonpath; |
||||
select '$ ? (@.a < 1e1)'::jsonpath; |
||||
select '$ ? (@.a < -1e1)'::jsonpath; |
||||
select '$ ? (@.a < +1e1)'::jsonpath; |
||||
select '$ ? (@.a < .1e1)'::jsonpath; |
||||
select '$ ? (@.a < -.1e1)'::jsonpath; |
||||
select '$ ? (@.a < +.1e1)'::jsonpath; |
||||
select '$ ? (@.a < 0.1e1)'::jsonpath; |
||||
select '$ ? (@.a < -0.1e1)'::jsonpath; |
||||
select '$ ? (@.a < +0.1e1)'::jsonpath; |
||||
select '$ ? (@.a < 10.1e1)'::jsonpath; |
||||
select '$ ? (@.a < -10.1e1)'::jsonpath; |
||||
select '$ ? (@.a < +10.1e1)'::jsonpath; |
||||
select '$ ? (@.a < 1e-1)'::jsonpath; |
||||
select '$ ? (@.a < -1e-1)'::jsonpath; |
||||
select '$ ? (@.a < +1e-1)'::jsonpath; |
||||
select '$ ? (@.a < .1e-1)'::jsonpath; |
||||
select '$ ? (@.a < -.1e-1)'::jsonpath; |
||||
select '$ ? (@.a < +.1e-1)'::jsonpath; |
||||
select '$ ? (@.a < 0.1e-1)'::jsonpath; |
||||
select '$ ? (@.a < -0.1e-1)'::jsonpath; |
||||
select '$ ? (@.a < +0.1e-1)'::jsonpath; |
||||
select '$ ? (@.a < 10.1e-1)'::jsonpath; |
||||
select '$ ? (@.a < -10.1e-1)'::jsonpath; |
||||
select '$ ? (@.a < +10.1e-1)'::jsonpath; |
||||
select '$ ? (@.a < 1e+1)'::jsonpath; |
||||
select '$ ? (@.a < -1e+1)'::jsonpath; |
||||
select '$ ? (@.a < +1e+1)'::jsonpath; |
||||
select '$ ? (@.a < .1e+1)'::jsonpath; |
||||
select '$ ? (@.a < -.1e+1)'::jsonpath; |
||||
select '$ ? (@.a < +.1e+1)'::jsonpath; |
||||
select '$ ? (@.a < 0.1e+1)'::jsonpath; |
||||
select '$ ? (@.a < -0.1e+1)'::jsonpath; |
||||
select '$ ? (@.a < +0.1e+1)'::jsonpath; |
||||
select '$ ? (@.a < 10.1e+1)'::jsonpath; |
||||
select '$ ? (@.a < -10.1e+1)'::jsonpath; |
||||
select '$ ? (@.a < +10.1e+1)'::jsonpath; |
Loading…
Reference in new issue