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 1iNLRj-0006hW-AE for pgsql-general@arkaria.postgresql.org; Wed, 23 Oct 2019 18:33:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iNLRg-0001qQ-Db for pgsql-general@arkaria.postgresql.org; Wed, 23 Oct 2019 18:33:20 +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 1iNLRg-0001qJ-0b for pgsql-general@lists.postgresql.org; Wed, 23 Oct 2019 18:33:20 +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 1iNLRV-0005Pf-EN for pgsql-general@lists.postgresql.org; Wed, 23 Oct 2019 18:33:18 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id A169F1085; Wed, 23 Oct 2019 20:33:06 +0200 (CEST) Date: Wed, 23 Oct 2019 20:33:06 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: jsonb_set() strictness considered harmful to data Message-ID: <20191023183306.GA26674@hjp.at> References: <20191019192723.luarxhq57qkzuncw@development> <1571560798575.47024@Optiver.com> <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> <20191022225513.GA12201@hjp.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6TrnltStXW4iwmi0" 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 --6TrnltStXW4iwmi0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-10-22 18:06:39 -0700, David G. Johnston wrote: > On Tue, Oct 22, 2019 at 3:55 PM Peter J. Holzer wrote: > 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. > > > > 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. >=20 > 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: >=20 > [...]=A0 >=20 >=20 > Throwing an exception for a pure function seems "un-SQLy" to me. In > particular, jsonb_set does something similar for json values as repla= ce > does for strings, so it should behave similarly. >=20 >=20 > Now if only the vast majority of users could have and keep this level of > understanding in mind while writing complex queries so that they remember= to > always add protections to compensate for the unique design decision that = SQL > has taken here... I grant that SQL NULL takes a bit to get used to. However, it is a core part of the SQL language and everyone who uses SQL must understand it (I don't remember when I first stumbled across "select * from t where c =3D NULL" returning 0 rows, but it was probably within the first few days of using a database). And personally I find it much easier to deal with concept which are applied consistently across the whole language than those which sometimes apply and sometimes don't seemingly at random, just because a developer thought it would be convenient for the specific use-case they had in mind. 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 --6TrnltStXW4iwmi0 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl2wnN0ACgkQ8g5IURL+ KF3uAg/+O6kY8cvWUxCEtebJCCyy5xnozpI4TfZMrw35qbKJxHt8dRbOx0RzmDJH UDObA+oR1e+reNlWt61RKmTuJHZXoHHU+5OFOjJORKSXOmI7HMNWY/o7qN1Xg5tH 3Sjij4MXVyv7zsiW4RtoRWu/pAV+VY8lkhs4tjCYXivf88onh9grYRFtXZPhEUFT 5CcDpqUaLQBLYKjOdd9dZ2M2I+70ASWGSVn3SwlS7HiZZauFnRnNdQrIcSMQnrdT gudyRywDfdQumzg5uLxJ+p13POTR802TsP0oP62hDe8bK+rvCo8vTZjz8GKluV9E G3Qofmc7Dl6bVgczNIenJlVo3aag/gXy15ZA5s6cOTPzlZpB6rCoOWjptKGIGSVg uW/jayHZdgJ01cHMjoia4MuxQuxZGyvwPqJuxU203jYU6qHWIGRHr2bY8r35Zx16 jpYe0G4FB/1wEV2pI2Q+MgJQbGcfyjDNkiH5iFyJ/csi4PPSx9+lk1GuA01kI0p/ S5DlNOzfrbGbj03rrUKmiaNmWk98OwsyLib69bp1cd5rRF/t/7nOK39S6dDQSY5x sEq/5rzf2/PWz62NXjCPi8nNzl5gBUvuV4nMtkfXdtr0ccYPBGzEPDY33x+5UetO 6SFOcoAnf1JBmuR6Y5WQP3ppugsW/NB/ldbEEMVK05EeHGG4mDM= =YoVN -----END PGP SIGNATURE----- --6TrnltStXW4iwmi0--