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 1iN33l-00078x-Pp for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 22:55:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iN33k-0007FK-9Q for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 22:55:24 +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 1iN33j-0007Cs-S4 for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 22:55:24 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iN33d-00034t-PF for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 22:55:22 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id B71041039; Wed, 23 Oct 2019 00:55:13 +0200 (CEST) Date: Wed, 23 Oct 2019 00:55:13 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: jsonb_set() strictness considered harmful to data Message-ID: <20191022225513.GA12201@hjp.at> References: <20191019161851.v7dwloiiav5yrpwu@development> <20191019192723.luarxhq57qkzuncw@development> <1571560798575.47024@Optiver.com> <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="vkogqOf2sHV7VnPd" 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 --vkogqOf2sHV7VnPd Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-10-20 13:20:23 -0700, Steven Pousty wrote: > I would think though that raising an exception is better than a default > behavior which deletes data. > As an app dev I am quite used to all sorts of "APIs" throwing exceptions = and > have learned to deal with them. >=20 > This is my way of saying that raising an exception is an improvement over= the > current situation. May not be the "best" solution but definitely an > improvement. I somewhat disagree. SQL isn't in general a language which uses exceptions a lot. It does have the value NULL to mean "unknown", and generally unknown combined with something else results in an unknown value again: % psql wds Null display is "(=E2=88=85)". Line style is unicode. Border style is 2. Unicode border line style is "double". Timing is on. Expanded display is used automatically. psql (11.5 (Ubuntu 11.5-3.pgdg18.04+1)) Type "help" for help. wds=3D> select 4 + 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=97 =E2=95=91 ?column? =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=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=9D (1 row) Time: 0.924 ms wds=3D> select replace('steven', 'e', 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=97 =E2=95=91 replace =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=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=9D (1 row) Time: 0.918 ms Throwing an exception for a pure function seems "un-SQLy" to me. In particular, jsonb_set does something similar for json values as replace does for strings, so it should behave similarly. 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 --vkogqOf2sHV7VnPd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl2viMwACgkQ8g5IURL+ KF36ZQ/5AdRSGEwh5740bN3RPImHYyDBbvkXWyMLigZTdzaD8CB2QHJDltgz/ySB FHPdKFYhQLiX7r09/XEZfuhfdJKG+P5+fPgAdgvCJ18F50ed91DsfOMXTNAaInGA 4ygx222Oub8uAhDw38JFiATdwW1QFkDGkTRLfAY3GgLYfWie7HBM5U56KY7ThygJ bTj8jfTLUvYlogfI4B/tYPkcwunZBreMUfOI36lZ33GEd2KUQ0iCjCpqrNrR4Fhe OAiBXoMYl6Jl8GcK83MGCFakQpSCrArL1+QzVirImeSwSmSkogevxF6Kojb3SKCT UFaBi5kQvp2ZDsXZ4IWf+Mk56ev2exKukCZzk49/Lxf301RA//D+HjUdT0yMj2L0 /IzU4KgIaVTGHILoGdhGxoTMhUvdnOX58KIPao6B5iGRDAMfwP0A2SuIcFNENCzx XtPGnntI9K96AqTVQPmreoYhl6GWGABdyooeo07WoQMa1zZSFj2TPzibSw1M+Jww iIMImwqR6D56NCzVXzFERl2TZqBMDhRVIzW5SPVzvU27JGzFNEoa8XJYacAr0ls3 0BoxYatO5X2+T7mqQv7eYyzS2PLZ/vGiyMzyxXgDTWddGyg+5R7QHMrMGrcyRWcK tWF0c4wHTT4a480K4ZWS9NlgIx2RjG7b07hbS32jHhcE3B8PqqU= =DAQV -----END PGP SIGNATURE----- --vkogqOf2sHV7VnPd--