Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hjMjH-0003Qx-Q0 for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 11:50:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hjMjF-00079G-6Z for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 11:50:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hjMjE-000799-Q0 for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2019 11:50:12 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hjMj6-0004Qg-CK for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2019 11:50:11 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id BAE532CFF; Fri, 5 Jul 2019 13:50:01 +0200 (CEST) Date: Fri, 5 Jul 2019 13:50:01 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Why does jsonb_set() remove non-mentioned keys? Message-ID: <20190705115001.3xjrsonpkuioujgl@hjp.at> References: <20190704220350.514a15a5@thenautilus.net> <20190705090047.41600de5@nautilus> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="hyehzy2btru3g7qa" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --hyehzy2btru3g7qa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-07-05 10:59:31 +0200, Thomas Kellerer wrote: > Gianni Ceccarelli schrieb am 05.07.2019 um 10:00: > >> strict functions with sql null inputs yield sql null output without > >> even executing the function > >=20 > > So when the SQL-level executor sees a call to any function declared > > strict with some NULL parameters, it doesn't call the function at > > all. `whatever_my_function('a string',1234,NULL)` is always `NULL` > >=20 >=20 > Ah, I see. Thanks for the clarification >=20 > Then I would question if declaring jsonb_set as "strict" makes sense I think it does but I raise the same question for to_jsonb. It's defined on anyelement and the documentation says: | Returns the value as json or jsonb. Arrays and composites are converted | (recursively) to arrays and objects; otherwise, if there is a cast from | the type to json, the cast function will be used to perform the | conversion; otherwise, a scalar value is produced. For any scalar type | other than a number, a Boolean, or a null value, the text representation | will be used, in such a fashion that it is a valid json or jsonb value. The documentation explicitely singles out "a number, a Boolean, or a null value", but doesn't specify how they are treated. I would expect that they are treated equivalently, though: An SQL number is converted to a JSON number, an SQL boolean is converted to JSON true or false and an SQL null is converted to JSON null. Returning SQL null instead of a JSON null breaks that expectation for no discernible reason. It also isn't consistent, since an SQL null in an array or composite is converted to a JSON null, as I would expect. hp --=20 _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson --hyehzy2btru3g7qa Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl0fOWIACgkQ8g5IURL+ KF3uvxAAnmNM/tv6zLuaWCuzhF14AEkzPLnsvfUo7Gl2+74hfYdRaRbxu13/oyyp o+GdcC2rf+P318KTXh7njPEExPuQtf4W1guhbhwRi8OPRA8NulyIoVMRiceQeUL5 1G+/CN7B8kNbLroTlQYp3gAT4RyJnES7uPteonJAjY8cChIOJU3jIc1qS2qXJsG0 p+gIBvmmknxpE6EEDEhehNa1ErDh93IfTV2/bQs2rAZ9iTrrTv7l+0kJjopQy0OI qXJCZUUTpgW+5xh7RvyFOVjdF9ePWfFA0DVnNtRT8WQRI0zRFzjQXCvUABVGb1en sa5BEmyxHm1JBAMnrUc6LFNwW84teXdSaeiOXBb+LZZACMWDxVQxVlV/chn9DhWt RPm+n2GxolnnOp0Gw0PVl6nmWb/3EFMEoMjq+mVMsFaej7Wib5xOTAvbXd56iXy4 KeWBk1nIefd8J5iL8GOcgBoFwv5P6NM5e5x2G86qiFtCIeKopAiM64ypiDYWcq6x 2uGfssBswZ4IlwUsN3mPZT+i667TGMcjiujNmvEUQEZo740t8lWzna+31DTs0OMy UCLrBjR+p+wkw9GbVOEE1/ooir6F5oLRfnTHWHyf7ofwmksvsD6ldBPhuC+JOCAx Y0JAmesAN9vKgx4MjSTowCsh2hL8dLncGAR/Ekpz2eXW5Wth/ak= =J84Y -----END PGP SIGNATURE----- --hyehzy2btru3g7qa--