Re: BUG #17660: JSONPATH issue using like_regex followed by the && operator

From: Shahar Belizon <shahar(at)cybear(dot)co>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17660: JSONPATH issue using like_regex followed by the && operator
Date: 2022-10-23 07:56:14
Message-ID: CAOaN=Vib3SuyPUcXNMUQb6NtftosEepPz6Yi6dy77Q6DmVs3dw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello Tom, and thank you for the quick response.
Well, I see what you are saying, but still, when checking the result of *SELECT
'a' ~ '\$$'* I'm getting a *FALSE, *so I expect the JSONPATH parser to work
the same way.
Furthermore, when checking regex101.com with *\$$* as the pattern and *a *as
the value I'm getting no match.

Best Regards,
Shahar

On Sat, 22 Oct 2022 at 16:48, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> > I've found an issue with the like_regex statement when using it together
> > with another && condition.
> > In the following example I'm expecting the result will end as:
> > [{"id":9,"value":"a"}] but instead, it ends with an empty array:
>
> > WITH a(attributes) AS (
> > SELECT '[{"id":9,"value":"a"},{"id":9,"value":"a$"}]'::jsonb
> > )
> > SELECT jsonb_path_query_array(attributes,'$[*] ? (!(@.id==9 && @.value
> > like_regex "\$$"))') FROM a
>
> I think you're short a backslash:
>
> =# WITH a(attributes) AS (
> SELECT '[{"id":9,"value":"a"},{"id":9,"value":"a$"}]'::jsonb
> )
> SELECT jsonb_path_query_array(attributes,'$[*] ? (!(@.id==9 && @.value
> like_regex "\\$$"))') FROM a
> ;
> jsonb_path_query_array
> ---------------------------
> [{"id": 9, "value": "a"}]
> (1 row)
>
> I believe one level of backslashing gets eaten by the jsonpath parser
> while parsing the literal, so your version ends as LIKE "$$" which
> is not different from LIKE "$" and will match every string.
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2022-10-23 15:31:45 Re: BUG #17660: JSONPATH issue using like_regex followed by the && operator
Previous Message PG Bug reporting form 2022-10-22 14:31:07 BUG #17661: Nothing provides 'libselinux.so.1(LIBSELINUX_1.0)(64bit)