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 1iN3A1-0007On-2y for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 23:01:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iN39z-0005ql-Kq for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 23:01:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iN39z-0005qe-AH for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 23:01:51 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iN39v-000396-LN for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 23:01:50 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 574111039; Wed, 23 Oct 2019 01:01:46 +0200 (CEST) Date: Wed, 23 Oct 2019 01:01:46 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: jsonb_set() strictness considered harmful to data Message-ID: <20191022230146.GB12201@hjp.at> References: <20191019192723.luarxhq57qkzuncw@development> <1571560798575.47024@Optiver.com> <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> <20191020233115.jjy6lqd4vsyrdbbo@raf.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="lEGEL1/lMxI0MVQ2" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --lEGEL1/lMxI0MVQ2 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-10-21 09:39:13 -0700, Steven Pousty wrote: > Turning a JSON null into a SQL null=C2=A0 and thereby "deleting" the data > is not the path of least surprises. But it doesn't do that: A JSON null is perfectly fine: wds=3D> select jsonb_set('{"a": 1, "b": 2}'::jsonb, '{c}', 'null'::jsonb); =E2=95=94=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=97 =E2=95=91 jsonb_set =E2=95=91 =E2=95=9F=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=95=A2 =E2=95=91 {"a": 1, "b": 2, "c": null} =E2=95=91 =E2=95=9A=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=9D (1 row) It is trying to replace a part of the JSON object with an SQL NULL (i.e. unknown) which returns SQL NULL: wds=3D> select jsonb_set('{"a": 1, "b": 2}'::jsonb, '{c}', NULL); =E2=95=94=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=97 =E2=95=91 jsonb_set =E2=95=91 =E2=95=9F=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=95=A2 =E2=95=91 (=E2=88=85) =E2=95=91 =E2=95=9A=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=9D (1 row) 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 --lEGEL1/lMxI0MVQ2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl2viloACgkQ8g5IURL+ KF1VAQ//ZQUa1vVLkip9Op1p5Q3oEyb5MRwQqbaaU6p1xZWiNzQbEG4HFhpEqzH8 q1vhrJquU5okQLXJcqA1Qh15wNR40AIFLdJtVPnZWOQ8npQj+gX/p3TYPntOB48M KutrXM2RY8yCmHpERPUrQt3mjhDp4gpXSGAw9WDwyipJczCHmhr2kJhKkIHBezQQ c3ZEiyg1Wq7p6fLqwyEqlXQHdNMArlotHvrhOEI/2bovVXjukERrw+GULnZbKsfM 39aKdI/py060+yEhIxkaArbwnffP2a3iBREOodrMiFY34IjzZT6mtPvkW0c8AJnm ivComddKqbKVvNFhgSkMGS9e5hqKOBy03Ve6NVwXWYOe22delAsRMSwGiZFe7KbV OIEuYq2wvnuvp3MYMDMdwZvYHwsMPf1CRCo3oJi5Hj5CGE+iN+Aajb2oM+MwvAEw s9Tttfk/tNOso0vqbRKl7I3O4XiQqwCa3rgRuFrD+UM6R0dIS5c/rvX20FbcCww7 zw7KG8Yt5t1S4CUfHabFiRJusf+0QjA4Mbx8rfa7sqkPuxMmg572rurPfRP+AaIK UbBaD2f6dNmEgBdMuBihKDbpva5m0AGrWWvODfbsF98grqHxlZ6UlbHqHpKrazm8 9vCI08NP1VBN8gB8E+Qm0r45hvo5B5GSRyeLTXqINohn6de33pQ= =fD8N -----END PGP SIGNATURE----- --lEGEL1/lMxI0MVQ2--