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 1iLc2Y-0002By-PY for pgsql-general@arkaria.postgresql.org; Fri, 18 Oct 2019 23:52:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iLc2W-0004Jq-GF for pgsql-general@arkaria.postgresql.org; Fri, 18 Oct 2019 23:52:12 +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 1iLc2W-0004Jh-6R for pgsql-general@lists.postgresql.org; Fri, 18 Oct 2019 23:52:12 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iLc2O-00037p-MW for pgsql-general@lists.postgresql.org; Fri, 18 Oct 2019 23:52:11 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 79E995F79F; Fri, 18 Oct 2019 19:51:59 -0400 (EDT) Date: Fri, 18 Oct 2019 19:51:59 -0400 From: Stephen Frost To: Ariadne Conill Cc: Adrian Klaver , "David G. Johnston" , Christoph Moench-Tegeder , "pgsql-generallists.postgresql.org" , feld@freebsd.org Subject: Re: jsonb_set() strictness considered harmful to data Message-ID: <20191018235159.GG6962@tamriel.snowman.net> References: <20191018215018.GB56427@elch.exwg.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="qNym1xKZJ2RAqaWB" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --qNym1xKZJ2RAqaWB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Ariadne Conill (ariadne@dereferenced.org) wrote: > On Fri, Oct 18, 2019 at 6:01 PM Adrian Klaver = wrote: > > https://www.postgresql.org/docs/11/functions-json.html > > " The field/element/path extraction operators return NULL, rather than > > failing, if the JSON input does not have the right structure to match > > the request; for example if no such element exists" >=20 > It is known that the extraction operators return NULL. The problem > here is jsonb_set() returning NULL when it encounters SQL NULL. >=20 > > Just trying to figure why one is worse then the other. >=20 > Any time a user loses data, it is worse. The preference for not > having data loss is why Pleroma uses PostgreSQL as it's database of > choice, as PostgreSQL has traditionally valued durability. If we > should not use PostgreSQL, just say so. Your contention that the documented, clear, and easily addressed behavior of a particular strict function equates to "the database system loses data and isn't durable" is really hurting your arguments here, not helping it. The argument about how it's unintuitive and can cause application developers to misuse the function (which is clearly an application bug, but perhaps an understandable one if the function interface isn't intuitive or is confusing) is a reasonable one and might be convincing enough to result in a change here. I'd suggest sticking to the latter argument when making this case. > > > I believe that anything that can be catastrophically broken by users > > > not following upgrade instructions precisely is a serious problem, and > > > can lead to serious problems. I am sure that this is not the only > > > project using JSONB which have had users destroy their own data in > > > such a completely preventable fashion. Let's be clear here that the issue with the upgrade instructions was that the user didn't follow your *application's* upgrade instructions, and your later code wasn't written to use the function, as documented, properly- this isn't a case of PG destroying your data. It's fine to contend that the interface sucks and that we should change it, but the argument that PG is eating data because the application sent a query to the database telling it, based on our documentation, to eat the data, isn't appropriate. Again, let's have a reasonable discussion here about if it makes sense to make a change here because the interface isn't intuitive and doesn't match what other systems do (I'm guessing it isn't in the SQL standard either, so we unfortunately can't look to that for help; though I'd hardly be surprised if they supported what PG does today anyway). As a practical response to the issue you've raised- have you considered using a trigger to check the validity of the new jsonb? Or, maybe, just made the jsonb column not nullable? With a trigger you could disallow non-null->null transistions, for example, or if it just shouldn't ever be null then making the column 'not null' would suffice. I'll echo Christoph's comments up thread too, though in my own language- these are risks you've explicitly accepted by using JSONB and writing your own validation and checks (or, not, apparently) rather than using what the database system provides. That doesn't mean I'm against making the change you suggest, but it certainly should become a lesson to anyone who is considering using primairly jsonb for their storage that it's risky to do so, because you're removing the database system's knowledge and understanding of the data, and further you tend to end up not having the necessary constraints in place to ensure that the data doesn't end up being garbage- thus letting your application destroy all the data easily due to an application bug. Thanks, Stephen --qNym1xKZJ2RAqaWB Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJdqlAeAAoJEO1sijiDR2RVm8QP/1ur+JKGsGvja2zNufr4mui3 drz8KFMdF/qQGD2an9tvn4fDjxAnj+pemN4smy8Ui6HGZUEjbJimudSkDhfAfB02 nOjZAtRsAQONYxXCZRM7uRd+r8EJg28X3uFEI9+Lk5LPUjH9xJr54xwwcGrVech4 bAxsijV5aVdWlj15a8ngyh8dUpWUgjtBNCqis67Wvu6QEntE1bKXIymipH90bmoh VMTDyHiloHyqFovxP2WgzSD+0T25WXTYiAA55ZSSSaq7rxXrr2gSuf39r/HdwuIh KvGrp6VnA4WuWJcuRfwvTk5EcaYkbHGwLx62WefPO/cT35cCpKbL9LEEV+4E5Cuw VkrevGx9teRO7nTQuZEGN0mvjVw9Xr0L0NA9qtp/aJ0Ves6cZZ938fskU7u/WQo5 Yxk9udyg7oyeSHKAIPmWjaGYGseqzcVK2R2sxOKCLjMfz93Md5/gdQco+2u4av1x DUZKXSWq3TcrWcA917dUt5m58pNyAubl5l8+ZD7hDLPTjOk3axfiOpoNJ9bVFu3O 55LI3J6k7xhzp5sRRrLVM7A1F/4ypF+EekZkTznPWVDZt1UCQIpLw8ynjXvp+WBV uux01pVbR0XYvIE1xujYnZsEvsGWneNXPtOoI8+yG767pzSVD0EWFtIhnGZFHzg4 wmdOj+Mo8Jvl3Zgch62H =0aMW -----END PGP SIGNATURE----- --qNym1xKZJ2RAqaWB--