Re: Variable substitution in jsonb functions fails for jsonpath operator like_regex - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Variable substitution in jsonb functions fails for jsonpath operator like_regex
Date
Msg-id 3157573.1697663770@sss.pgh.pa.us
Whole thread Raw
In response to Variable substitution in jsonb functions fails for jsonpath operator like_regex  (Erwin Brandstetter <brsaweda@gmail.com>)
Responses Re: Variable substitution in jsonb functions fails for jsonpath operator like_regex  (Jeff Janes <jeff.janes@gmail.com>)
List pgsql-bugs
Erwin Brandstetter <brsaweda@gmail.com> writes:
> The functions jsonb_path_exists() and friends accept a "vars" parameter for
> parameter substitution in the jsonpath argument. This seems to work for all
> jsonpath operators except "like_regex":

> SELECT * FROM tbl
> WHERE  jsonb_path_exists(data, '$[*].value ? (@ like_regex $foo)', '{"foo":
> "CEO"}');

>> ERROR:  syntax error at or near "$foo" of jsonpath input
>> LINE 3: WHERE  jsonb_path_exists(data, '$[*].value ? (@ like_regex $...

> Notably, the same works even for "starts with":


Hmm, maybe just an oversight in jsonpath_gram.y?

predicate:
    ...
    | expr STARTS_P WITH_P starts_with_initial
    | expr LIKE_REGEX_P STRING_P
    | expr LIKE_REGEX_P STRING_P FLAG_P STRING_P
    ;

starts_with_initial:
    STRING_P                        { $$ = makeItemString(&$1); }
    | VARIABLE_P                    { $$ = makeItemVariable(&$1); }
    ;

Maybe it wouldn't take more than s/STRING_P/starts_with_initial/
here (though I'd then rename starts_with_initial to something
more generic).  With bad luck there might be some dependency on
this restriction downstream of the grammar, but I suspect not.
Didn't try though.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: BUG #18160: first create table show "ERROR: permission denied for schema public", next create table works
Next
From: Jeff Janes
Date:
Subject: Re: Variable substitution in jsonb functions fails for jsonpath operator like_regex