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 1sIJBq-00Eda5-4R for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Jun 2024 02:30:50 +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 1sIJAo-008rXQ-Bm for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Jun 2024 02:29:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::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 1sIJAn-008rXH-MI for pgsql-hackers@lists.postgresql.org; Sat, 15 Jun 2024 02:29:46 +0000 Received: from 009.lax.mailroute.net ([199.89.1.12]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sIJAg-001Mve-S3 for pgsql-hackers@lists.postgresql.org; Sat, 15 Jun 2024 02:29:45 +0000 Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4W1Kq547wtzlgMVX; Sat, 15 Jun 2024 02:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:in-reply-to :mime-version:user-agent:date:date:message-id:from:from :references:subject:subject:received:received; s=mr01; t= 1718418576; x=1721010577; bh=NCArX0vpeh+IhMFQQICyzh/81f4b8HLG4sV JRChZfws=; b=ShY8SK76+kGm91bN07oKkgdCUmc9BiZ6hwvyjxlpn4HnlgiR9QP 4k6EdODOsnkPBlrk7d5lALkuAVoUWlP39ib/fbVhGN2nmkkTQil7v1CqIGii4nhs yRYljrra0bX/zjuCRlz1tvXvm44A3+cUWpCWYTCJAwEq9un7hEfZhfIJ8+iXMUEr mljs5aJZqfvJkY0xcCqQQ6L9P7eQS1Z+y5a/eUAgVwQitPdpbWjO6ahEqgfU9FjB qCDLuA3qfZK2Aapsj/77q4lxpRWV+SMQbUrAav4g4Iptz5Y46naa+JE0czufU+WA u4VqZvv+7crbsExpYaZ9Lq4M0uF6glvU4WQ== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 6Oe93y18I0Xc; Sat, 15 Jun 2024 02:29:36 +0000 (UTC) Received: from [73.103.120.3] (c-73-103-120-3.hsd1.in.comcast.net [73.103.120.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jcflack@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4W1Kq40vFyzlgMVV; Sat, 15 Jun 2024 02:29:35 +0000 (UTC) Subject: Re: jsonpath: Missing regex_like && starts with Errors? To: "David E. Wheeler" , PostgreSQL Hackers References: <9272D3A9-8805-4DE1-A95F-84EB210EC121@justatheory.com> From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <666CFC8E.1000108@acm.org> Date: Fri, 14 Jun 2024 22:29:34 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <9272D3A9-8805-4DE1-A95F-84EB210EC121@justatheory.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 06/14/24 12:21, David E. Wheeler wrote: > I noticed that neither `regex_like` nor `starts with`, the jsonpath ope= rators, raise an error when the operand is not a string (or array of stri= ngs): >=20 > david=3D# select jsonb_path_query('true', '$ like_regex "^hi"'); > jsonb_path_query=20 > ------------------ > null > (1 row) >=20 > david=3D# select jsonb_path_query('{"x": "hi"}', '$ starts with "^hi"')= ; > jsonb_path_query=20 > ------------------ > null > (1 row) To begin with, both of those path queries should have been rejected at the parsing stage, just like the one David Johnson pointed out: On 06/13/24 22:14, David G. Johnston wrote: > On Thursday, June 13, 2024, Chapman Flack wrote: >> On 06/13/24 21:46, David G. Johnston wrote: >>>>> david=3D# select jsonb_path_query('1', '$ >=3D 1'); >>>> >>>> Good point. I can't either. No way I can see to parse that as >>>> a . >>> >>> Whether we note it as non-standard or not is an open question then, b= ut >> it >>> does work and opens up a documentation question. All of these are appearing where a is needed, and that's not allowed in the standard. Strictly speaking, the only place can appear is within . So I should go look at our code to see what grammar we've implemented, exactly. It is beginning to seem as if we have simply added as another choice for an expression, not restricted to only appearing in a filter. If so, and we add documentation about how we diverge from the standard, that's probably the way to say it. On 06/13/24 22:14, David G. Johnston wrote: > I don=E2=80=99t get why the outcome of a boolean producing operation is= n=E2=80=99t just > generally allowed to be produced I understand; after all, what is a 'predicate' but another 'boolean producing operation'? But the committee (at least in this edition) has stuck us with this clear division in the grammar: there is no , boolean as it may be, that can appear as a , and there is no that can appear outside of a filter and be treated as a boolean-valued expression. As for the error behavior of a (which strictly, again, can only appear inside a ), the standard says what seems to be the same thing, in a couple different ways. In 4.48.5 Overview of SQL/JSON path language, this is said: "The SQL/JSON path language traps any errors that occur during the evaluation of a . Depending on the precise = ... the result may be Unknown, True, or False, ...". Later in 9.46's General Rules where the specific semantics of the various predicates are laid out, each predicate has rules spelling out which of Unknown, True, or False results when an error condition is encountered (usually Unknown, except where something already seen allows returning True or False). Finally, the itself collapses the three-valued logic to two; it includes the items for which the predicate returns True, and excludes them for False or Unknown. So that's where the errors went. The question of what should happen to the errors when a appears outside of a of course isn't answered in the standard, because that's not supposed to be possible. So if we're allowing predicates to appear on their own as expressions, it's also up to us to say what should happen with errors when they do. Regards, -Chap