Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qtDw4-00BRKL-IU for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Oct 2023 21:18:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qtDvy-009Cyw-GZ for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Oct 2023 21:18:31 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qtDvy-009Cyo-8F for pgsql-bugs@lists.postgresql.org; Wed, 18 Oct 2023 21:18:30 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qtDtj-001QZ5-88 for pgsql-bugs@lists.postgresql.org; Wed, 18 Oct 2023 21:16:14 +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 39ILGA7v3157574; Wed, 18 Oct 2023 17:16:10 -0400 From: Tom Lane To: Erwin Brandstetter cc: pgsql-bugs@lists.postgresql.org Subject: Re: Variable substitution in jsonb functions fails for jsonpath operator like_regex In-reply-to: References: Comments: In-reply-to Erwin Brandstetter message dated "Wed, 18 Oct 2023 21:07:34 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3157572.1697663770.1@sss.pgh.pa.us> Date: Wed, 18 Oct 2023 17:16:10 -0400 Message-ID: <3157573.1697663770@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Erwin Brandstetter writes: > The functions jsonb_path_exists() and friends accept a "vars" parameter for > parameter substitution in the jsonpath argument. This seems to work for all > jsonpath operators except "like_regex": > SELECT * FROM tbl > WHERE jsonb_path_exists(data, '$[*].value ? (@ like_regex $foo)', '{"foo": > "CEO"}'); >> ERROR: syntax error at or near "$foo" of jsonpath input >> LINE 3: WHERE jsonb_path_exists(data, '$[*].value ? (@ like_regex $... > Notably, the same works even for "starts with": Hmm, maybe just an oversight in jsonpath_gram.y? predicate: ... | expr STARTS_P WITH_P starts_with_initial | expr LIKE_REGEX_P STRING_P | expr LIKE_REGEX_P STRING_P FLAG_P STRING_P ; starts_with_initial: STRING_P { $$ = makeItemString(&$1); } | VARIABLE_P { $$ = makeItemVariable(&$1); } ; Maybe it wouldn't take more than s/STRING_P/starts_with_initial/ here (though I'd then rename starts_with_initial to something more generic). With bad luck there might be some dependency on this restriction downstream of the grammar, but I suspect not. Didn't try though. regards, tom lane