The jsonpath predicate `like_regex` does not accept variables for pattern (or flags)
От | sulfinu@gmail.com |
---|---|
Тема | The jsonpath predicate `like_regex` does not accept variables for pattern (or flags) |
Дата | |
Msg-id | CAGH1kmz2QT+m2Lr8ts=YWDq+435JWZ2MPFE2WpS2yFh2HQrQ5g@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: The jsonpath predicate `like_regex` does not accept variables for pattern (or flags)
Re: The jsonpath predicate `like_regex` does not accept variables for pattern (or flags) |
Список | pgsql-bugs |
Hello,
this one is noticed on PostgreSQL 16.3.
One of the predicates that can be used in jsonpath expressions is like_regex, which unfortunately does not accept variables for pattern or flags:
SELECT jsonb_path_match('{"name":"abc"}'::jsonb, '$.name like_regex $p flag "q"', '{"p": "abc"}'::jsonb, true);
SELECT jsonb_path_match('{"name":"abc"}'::jsonb, '$.name like_regex "abc" flag $f', '{"p": "abc", "f": "q"}'::jsonb, true);
The starts with predicate on the other hand accepts variables for prefix (but not for the tested string):
SELECT jsonb_path_match('{"name":"abc"}'::jsonb, '$.name starts with $p', '{"p": "abc"}'::jsonb, true);
I would like to be able to use a variable inside the like_regex predicate, at least for the pattern. I need that since I generate dynamically the involved predicates and this one is a containment test, actually.
If someone worries about self-shooting in the foot, I have two answers to that:
- it's my (calculated) risk;
- I can already shoot myself in the foot with the plain SQL regular expression test - see
`SELECT regexp_like('abc', $1, $2);` with parameters ["abc", "q"]
or`SELECT 'abc' ~ $1` with parameters ["abc"]
Thank you.
В списке pgsql-bugs по дате отправления: