Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fabe0d6

Browse files
feodorNikita Glukhov
authored and
Nikita Glukhov
committed
fix support () in jsonpath expression
1 parent 08d2b93 commit fabe0d6

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ checkScalarEquality(JsonbValue *jb1, JsonbValue *jb2)
212212
case jbvNumeric:
213213
return (compareNumeric(jb1->val.numeric, jb2->val.numeric) == 0);
214214
default:
215-
elog(ERROR,"Wrong state");
215+
elog(ERROR,"1Wrong state");
216216
return false;
217217
}
218218
}
@@ -843,7 +843,7 @@ recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
843843
}
844844
break;
845845
default:
846-
elog(ERROR,"Wrong state: %d", jsp->type);
846+
elog(ERROR,"2Wrong state: %d", jsp->type);
847847
}
848848

849849
return res;

src/backend/utils/adt/jsonpath_gram.y

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ makeAny(int first, int last)
213213
%token <str> LESS_P LESSEQUAL_P EQUAL_P NOTEQUAL_P GREATEREQUAL_P GREATER_P
214214
%token <str> ANY_P
215215

216-
%type <value> result jsonpath scalar_value path_primary expr
216+
%type <value> result jsonpath scalar_value path_primary expr pexpr
217217
array_accessor any_path accessor_op key unary_expr
218218
predicate delimited_predicate
219219

@@ -268,7 +268,7 @@ delimited_predicate:
268268

269269
predicate:
270270
delimited_predicate { $$ = $1; }
271-
| expr comp_op expr { $$ = makeItemBinary($2, $1, $3); }
271+
| pexpr comp_op pexpr { $$ = makeItemBinary($2, $1, $3); }
272272
// | expr LIKE_REGEX pattern { $$ = ...; }
273273
// | expr STARTS WITH STRING_P { $$ = ...; }
274274
// | expr STARTS WITH '$' STRING_P { $$ = ...; }
@@ -298,13 +298,18 @@ unary_expr:
298298
| '-' unary_expr { $$ = makeItemUnary(jpiMinus, $2); }
299299
;
300300

301+
pexpr:
302+
expr { $$ = $1; }
303+
| '(' expr ')' { $$ = $2; }
304+
;
305+
301306
expr:
302307
unary_expr { $$ = $1; }
303-
| expr '+' expr { $$ = makeItemBinary(jpiAdd, $1, $3); }
304-
| expr '-' expr { $$ = makeItemBinary(jpiSub, $1, $3); }
305-
| expr '*' expr { $$ = makeItemBinary(jpiMul, $1, $3); }
306-
| expr '/' expr { $$ = makeItemBinary(jpiDiv, $1, $3); }
307-
| expr '%' expr { $$ = makeItemBinary(jpiMod, $1, $3); }
308+
| pexpr '+' pexpr { $$ = makeItemBinary(jpiAdd, $1, $3); }
309+
| pexpr '-' pexpr { $$ = makeItemBinary(jpiSub, $1, $3); }
310+
| pexpr '*' pexpr { $$ = makeItemBinary(jpiMul, $1, $3); }
311+
| pexpr '/' pexpr { $$ = makeItemBinary(jpiDiv, $1, $3); }
312+
| pexpr '%' pexpr { $$ = makeItemBinary(jpiMod, $1, $3); }
308313
;
309314

310315
index_elem:

0 commit comments

Comments
 (0)