From: Tom Lane <tgl@sss.pgh.pa.us>
To: shahar@cybear.co
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17660: JSONPATH issue using like_regex followed by the && operator
Date: Sat, 22 Oct 2022 09:48:46 -0400
Message-ID: <3367660.1666446526@sss.pgh.pa.us> (raw)
In-Reply-To: <17660-3fe48447b080d5b6@postgresql.org>
References: <17660-3fe48447b080d5b6@postgresql.org>
PG Bug reporting form <noreply@postgresql.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
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, shahar@cybear.co, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17660: JSONPATH issue using like_regex followed by the && operator
In-Reply-To: <3367660.1666446526@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