Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1omErt-0003oN-Ur for pgsql-bugs@arkaria.postgresql.org; Sat, 22 Oct 2022 13:48:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1omErs-0001Fc-S0 for pgsql-bugs@arkaria.postgresql.org; Sat, 22 Oct 2022 13:48:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1omErs-0001FT-Ju for pgsql-bugs@lists.postgresql.org; Sat, 22 Oct 2022 13:48:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1omErp-0008DU-HH for pgsql-bugs@lists.postgresql.org; Sat, 22 Oct 2022 13:48:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 29MDmkdo3367661; Sat, 22 Oct 2022 09:48:46 -0400 From: Tom Lane To: shahar@cybear.co cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17660: JSONPATH issue using like_regex followed by the && operator In-reply-to: <17660-3fe48447b080d5b6@postgresql.org> References: <17660-3fe48447b080d5b6@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sat, 22 Oct 2022 11:55:24 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3367659.1666446526.1@sss.pgh.pa.us> Date: Sat, 22 Oct 2022 09:48:46 -0400 Message-ID: <3367660.1666446526@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form 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