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 1jjSQx-00053o-24 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jun 2020 19:00:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jjSQv-0007nm-Vm for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jun 2020 19:00:13 +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 1jjSQv-0007nf-O4 for pgsql-hackers@lists.postgresql.org; Thu, 11 Jun 2020 19:00:13 +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 1jjSQo-0006dt-1Z for pgsql-hackers@lists.postgresql.org; Thu, 11 Jun 2020 19:00:13 +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 05BJ0363355115; Thu, 11 Jun 2020 15:00:03 -0400 From: Tom Lane To: Alexander Korotkov cc: PostgreSQL Hackers Subject: Re: jsonpath versus NaN In-reply-to: References: <203949.1591879542@sss.pgh.pa.us> Comments: In-reply-to Alexander Korotkov message dated "Thu, 11 Jun 2020 21:41:00 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <355113.1591902003.1@sss.pgh.pa.us> Date: Thu, 11 Jun 2020 15:00:03 -0400 Message-ID: <355114.1591902003@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alexander Korotkov writes: > On Thu, Jun 11, 2020 at 3:45 PM Tom Lane wrote: >> It is entirely clear from the code, the documentation, >> and the relevant RFCs that JSONB does not allow NaNs as numeric >> values. > The JSONB itself doesn't store number NaNs. It stores the string "NaN". Yeah, but you have a numeric NaN within the JsonbValue tree between executeItemOptUnwrapTarget and convertJsonbScalar. Who's to say that that illegal-per-the-data-type structure won't escape to somewhere else? Or perhaps more likely, that we'll need additional warts in other random places in the JSON code to keep from spitting up on the transiently invalid structure. > I found the relevant part of the standard. Unfortunately, I can't > post the full standard here due to its license, but I think I can cite > the relevant part. I don't think this is very relevant. The SQL standard has not got the concepts of Inf or NaN either (see 4.4.2 Characteristics of numbers), therefore their definition is only envisioning that a string representing a normal finite number should be castable to DOUBLE PRECISION. Thus, both of the relevant standards think that "numbers" are just finite numbers. So when neither JSON nor SQL consider that "NaN" is an allowed sort of number, why are you doing violence to the code to allow it in a jsonpath? And if you insist on doing such violence, why didn't you do some more and kluge it to the point where "Inf" would work too? (It would require slightly less klugery in the wake of the infinities- in-numeric patch that I'm going to post soon ... but that doesn't make it a good idea.) regards, tom lane