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 1jm1XO-0005j7-CO for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2020 20:53:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jm1XM-000230-80 for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2020 20:53:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jm1XL-000224-OU for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2020 20:53:28 +0000 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jm1XE-0003Em-Nz for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2020 20:53:26 +0000 Received: by mail-ot1-x343.google.com with SMTP id n70so5660357ota.5 for ; Thu, 18 Jun 2020 13:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:cc:references:autocrypt:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=WPY7v3g3EfD+ekwLPbNZHexgi1zooH6DbdrFwteLbno=; b=SMGmCA/0xtq9vAnPI7mO4AWbyY+G94Y/gwI+CA0x5vfMEtpcETvPpuIpsMFx6jvkPO 8psi24wa5PbN++fVrUWiGE0vRcX8rL4lLlsOhYbGTa2NUhamatzWoYdh9KMcaRhcf23R MUPK6QZ01PNdQ9j0b8ooXhL4YONmOGvN3qdax9iTy5PW0z7JR8MerocrdDwPkeCKq1a8 NNAey+4s1fcuKwZD3UpcAVjAo9rI92El0CN6Ie1Z9O4fthwTuzd7y66eiIvjI9R/ersf 0qjysgaKwESvpypfnF+KVShdddXiemixVrlRhZ2kA9PQYPMahRQBUDeV0p6EHY940zWm 94RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=WPY7v3g3EfD+ekwLPbNZHexgi1zooH6DbdrFwteLbno=; b=A+Y9aNfHti0WMrB80ilptjw7aJj/hAEpKcc9Xj8iZVXPF1Q74yJi1DhStyTz8TneYG 9fw6RN/x0GeFYpS+6X0DDc/eHAp/TUtb1TvD8/05Mj/7t0sDInl0513i1GzB+c5wgJh5 rpOQij+7sWGNZvhSGyV0mHKVb6ly2wb9OPJLxtCvAmTRknZ2Gqlejay3Dxb+rt4vI5pw d2/k0McV8bzEt23ElGq7NIH6eUKa5JsNJdEqGSW27+svRwpQ0KgwiiaO5vPH1eJuXNsi R2sizI0mL+KAgJKABhnaPuf2FxrkMeAO1MyqBiazPAi1IStsoHslgkpM44CErn6YYAab 5Qiw== X-Gm-Message-State: AOAM530+FgB9gK8X5Gpbsrvn7nZbvKig0sIIeKkymxC7JVMezB2Yem0/ Pp/U8zrMLd3QceXGvB1gd9pF8fFPtJQ6tpviDbiG+G0e7iEmPbR8MFEEa1lOueMv9Pem0flnPXU /F48+PKanQF3ePCTKre9u+s64jR6haRIAOW7UXzpyCIu73KE/x5NzpvVYkmHdvu6ILmoZDmuhtP 7MwtpmPy4sdDfT5ITGl6U4MN4= X-Google-Smtp-Source: ABdhPJxnshj67+NYy5ls5sI5vyD4paVyJGGJGpDAIdTvh/31u518DJ7VDRnWktucga/gdwrwDIF8xA== X-Received: by 2002:a9d:1b1:: with SMTP id e46mr508722ote.332.1592513598684; Thu, 18 Jun 2020 13:53:18 -0700 (PDT) Received: from [192.168.10.146] (99-10-92-30.lightspeed.rlghnc.sbcglobal.net. [99.10.92.30]) by smtp.gmail.com with ESMTPSA id o4sm877868oie.19.2020.06.18.13.53.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Jun 2020 13:53:17 -0700 (PDT) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: jsonpath versus NaN To: Tom Lane , Robert Haas Cc: Oleg Bartunov , Alexander Korotkov , PostgreSQL Hackers References: <203949.1591879542@sss.pgh.pa.us> <355114.1591902003@sss.pgh.pa.us> <1446772.1592407984@sss.pgh.pa.us> <1553053.1592498154@sss.pgh.pa.us> Autocrypt: addr=andrew.dunstan@2ndQuadrant.com; prefer-encrypt=mutual; keydata= mQENBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0DGJCR/iUOl/N62Kh4855zZC7NHIjQHPOvV5Stz/l5ilDhvGVk+xkXFPys SjZoUr1rXhYLpiyi5sR0X9FHXT0KnGuz1F5ERO7ZTLSSQ6fJwPj6gOk9K+vvoKvoeql5ABEB AAG0L0FuZHJldyBEdW5zdGFuIDxhbmRyZXcuZHVuc3RhbkAybmRRdWFkcmFudC5jb20+iQFY BBMBAgBCAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgBYhBOQ+WEYd/Hy/RGkVpZn6f8tZ /DuBAhkBBQJd1pSYBQkSzqMsAAoJEJn6f8tZ/DuBJmEIAIVFBIC3qGqh+YTPVTkfowwxpHz0 tZSPjZ6GS/5y62kgoZrZOVXw+Rg2ceuMM3a+In/RRjTx4bembgYqRKgzXlDfiNBJeq5ioVuN H1faDKE2lm5a6QkRQ2JU6DKf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Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <1553053.1592498154@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 6/18/20 12:35 PM, Tom Lane wrote: > Robert Haas writes: >> On Thu, Jun 18, 2020 at 11:51 AM Oleg Bartunov wrote: >>> The problem is that we tried to find a trade-off between standard and postgres >>> implementation, for example, in postgres CAST allows NaN and Inf, and SQL Standard >>> requires .double should works as CAST. >> It seems like the right thing is to implement the standard, not to >> implement whatever PostgreSQL happens to do in other cases. I can't >> help feeling like re-using the numeric data type for other things has >> led to this confusion. I think that fails in other cases, too: like >> what if you have a super-long integer that can't be represented as a >> numeric? I bet jsonb will fail, or maybe it will convert it to a >> string, but I don't see how it can do anything else. > Actually, the JSON spec explicitly says that any number that doesn't fit > in an IEEE double isn't portable [1]. So we're already very far above and > beyond the spec's requirements by using numeric. We don't need to improve > on that. But I concur with your point that just because PG does X in > some other cases doesn't mean that we must do X in json or jsonpath. > > regards, tom lane > > [1] https://tools.ietf.org/html/rfc7159#page-6 > > This specification allows implementations to set limits on the range > and precision of numbers accepted. Since software that implements > IEEE 754-2008 binary64 (double precision) numbers [IEEE754] is > generally available and widely used, good interoperability can be > achieved by implementations that expect no more precision or range > than these provide, in the sense that implementations will > approximate JSON numbers within the expected precision. A JSON > number such as 1E400 or 3.141592653589793238462643383279 may indicate > potential interoperability problems, since it suggests that the > software that created it expects receiving software to have greater > capabilities for numeric magnitude and precision than is widely > available. > > Note that when such software is used, numbers that are integers and > are in the range [-(2**53)+1, (2**53)-1] are interoperable in the > sense that implementations will agree exactly on their numeric > values. > Just to complete the historical record, that standard wasn't published at the time we created the JSON type, and the then existing standard (rfc4627) contains no such statement. We felt it was important to be able to represent any Postgres data value in as natural a manner as possible given the constraints of JSON. rfc7159 was published just as we were finalizing 9.4 with JSONB, although I'm not sure it made a heavy impact on our consciousness. If it had I would still not have wanted to impose any additional limitation on numerics. If you want portable numbers cast the numeric to double before producing the JSON. ISTR having a conversation about the extended use of jsonb in jsonpath a while back, although I don't remember if that was on or off list. I know it troubled me some. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services