Hello,
this one is noticed on PostgreSQL 16.3.
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.