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 1iLmbG-000194-9p for pgsql-general@arkaria.postgresql.org; Sat, 19 Oct 2019 11:08:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iLmbE-0003eo-ET for pgsql-general@arkaria.postgresql.org; Sat, 19 Oct 2019 11:08:44 +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 1iLmbD-0003V4-NP for pgsql-general@lists.postgresql.org; Sat, 19 Oct 2019 11:08:43 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iLmb5-0000e8-PZ for pgsql-general@lists.postgresql.org; Sat, 19 Oct 2019 11:08:41 +0000 Received: by mail-wr1-x443.google.com with SMTP id o15so8365895wru.5 for ; Sat, 19 Oct 2019 04:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YZ/5vmxBFqJzC0jZixeTs7jtjJIS9lkuqCQuK7STObo=; b=Bp6VTVuwUT/5vaAvyvbgt4ABEOu4tSdNbqcA5TTSXlkxY6Vt8UWU4HXBUFecs8Bh0e 05v2vNZ39rbURu34yrMl0VrRyK6cgxp2DU984fZXWIi1zNgu00YtalPQZFKDGqhWgstt 8IcZVfsUJog/39rthdVPog33+z/QFP1qD87rJeiAcfb89IC25+jo87P8/bpSJ9/H+FoO gIrXt6RECetXeQUSIUdtrSG6cDn2X2hajjHcUFitFrRxMSxj4oj1e18u9GhMdlSr7lM0 oyNohN5rPmp774TXX1KSEcynqdCqsuLUMinElJ/sD+Xfb/TVH63dGJvCalqhF1KY5bIT Aifw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YZ/5vmxBFqJzC0jZixeTs7jtjJIS9lkuqCQuK7STObo=; b=kLYp/j6D9DPwhMxfzHMtJXuqc7A8qSdhOwIqJFsufjAwMe3xLKtdq4btG9Gt2jmWAb Stj/19YbbUv+pFuGam1p/AMK/V4kR80XGcAYQDQPdmA7A3+oGe7SnZhK3z8Tiecqv82P lca61tVJBnxYsyOPUxKEMgdqCmBtMjrbgCc/b6qrpbbnPC3LPeTGLhf5jJOs+P8QAlKX APqMpimoP27DAqAUaGrrDWRGqK3Jdfx4Jkgc6HwTCsxhWl1g0udHQngpPLc8D764fN79 udxpBV7C+8NZsLJ7D+OKlFLpf8QDFdfJ2yd3B42gw0LTAWdigT74Is28NaA2B+jJVnpH u7CQ== X-Gm-Message-State: APjAAAUoM5Wa0xHknc3iNHQ1asIVw12W1QvvK6nf77PYTPyZHZCJ61Bp 9kzPNn7AbCMDbbuCuvBQb8LmGA== X-Google-Smtp-Source: APXvYqzqnP2heza3FelLDLr9hR0PeIsJQIVYSYcE/DOMNr/7RRKJW/DM+d1HZosdEfXSxOdEDE4hpA== X-Received: by 2002:adf:e50a:: with SMTP id j10mr124151wrm.352.1571483314219; Sat, 19 Oct 2019 04:08:34 -0700 (PDT) Received: from localhost (cst-prg-73-11.cust.vodafone.cz. [46.135.73.11]) by smtp.gmail.com with ESMTPSA id 74sm12594876wrm.92.2019.10.19.04.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Oct 2019 04:08:33 -0700 (PDT) Date: Sat, 19 Oct 2019 13:08:31 +0200 From: Tomas Vondra To: Ariadne Conill Cc: Stephen Frost , 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: <20191019110831.7y7d2yys5xlujqw6@development> References: <20191018215018.GB56427@elch.exwg.net> <20191018235159.GG6962@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Oct 18, 2019 at 09:14:09PM -0500, Ariadne Conill wrote: >Hello, > >On Fri, Oct 18, 2019 at 6:52 PM Stephen Frost wrote: >> >> 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" >> > >> > It is known that the extraction operators return NULL. The problem >> > here is jsonb_set() returning NULL when it encounters SQL NULL. >> > >> > > Just trying to figure why one is worse then the other. >> > >> > 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). > >Okay, I will admit that saying PG is eating data is perhaps >hyperbolic, My experience is that using such hyperbole is pretty detrimental, even when one is trying to make a pretty sensible case. The problem is that people often respond in a similarly hyperbolic claims, particularly when you hit a nerve. And that's exactly what happened here, becase we're *extremely* sensitive about data corruption issues, so when you claim PostgreSQL is "eating data" people are likely to jump on you, beating you with the documentation stick. It's unfortunate, but it's also entirely predictable. >but I will also say that the behaviour of jsonb_set() >under this type of edge case is unintuitive and frequently results in >unintended data loss. So, while PostgreSQL is not actually eating the >data, it is putting the user in a position where they may suffer data >loss if they are not extremely careful. > >Here is how other implementations handle this case: > >MySQL/MariaDB: > >select json_set('{"a":1,"b":2,"c":3}', '$.a', NULL) results in: > {"a":null,"b":2,"c":3} > >Microsoft SQL Server: > >select json_modify('{"a":1,"b":2,"c":3}', '$.a', NULL) results in: > {"b":2,"c":3} > >Both of these outcomes make sense, given the nature of JSON objects. >I am actually more in favor of what MSSQL does however, I think that >makes the most sense of all. > I do mostly agree with this. The json[b]_set behavior seems rather surprising, and I think I've seen a couple of cases running into exactly this issue. I've solved that with a simple CASE, but maybe changing the behavior would be better. That's unlikely to be back-patchable, though, so maybe a better option is to create a non-strict wrappers. But that does not work when the user is unaware of the behavior :-( regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services