From: Tom Lane <tgl@sss.pgh.pa.us>
To: Erwin Brandstetter <brsaweda@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Variable substitution in jsonb functions fails for jsonpath operator like_regex
Date: Wed, 18 Oct 2023 17:16:10 -0400
Message-ID: <3157573.1697663770@sss.pgh.pa.us> (raw)
In-Reply-To: <CAGHENJ4A8awD2uXHkf50eV+9wyiDm3eP+G10J09+0VRmXBQAdw@mail.gmail.com>
References: <CAGHENJ4A8awD2uXHkf50eV+9wyiDm3eP+G10J09+0VRmXBQAdw@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, brsaweda@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Variable substitution in jsonb functions fails for jsonpath operator like_regex
In-Reply-To: <3157573.1697663770@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox