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 1iMHf6-0002mZ-9r for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Oct 2019 20:18:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iMHf4-0001HZ-4q for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Oct 2019 20:18:46 +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 1iMHf3-0001HQ-SX for pgsql-hackers@lists.postgresql.org; Sun, 20 Oct 2019 20:18:45 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMHf1-0004bW-Il for pgsql-hackers@lists.postgresql.org; Sun, 20 Oct 2019 20:18:45 +0000 Received: by mail-wr1-x441.google.com with SMTP id r3so11512667wrj.6 for ; Sun, 20 Oct 2019 13:18:43 -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:content-transfer-encoding:in-reply-to :user-agent; bh=s/McZlVVjdxNyTIUHX9RRvYVGRo8R2JXZZfX3gG93e8=; b=D9sHqgcK+RSykUSeeXrOM7XpvNMHa8ULwkmJ4+KapKy0GoU+n1lZ7ayoucLAHrSMSy 9vIdQM3UoeR09nt1+otywK/0DolQnitgIfKS6kJzfmmVAsFxb1T8qs8FWLoM2Yg7TA/q bGd21qWkruiDTSG8C2g4S6yvLytQKApOyWfCQi+twFDdd/+DWqPG3rVQrDNRH6ojSelZ t9opp+35mEI/v3lDwNWKZB3wQueabzNzor81yNdc9/9SrKIZejVFWOOS+HQjKPKX7RcY vwNt0/QnxB08aBbiyjDTStqokeU+vCqz80PXEkQ2cjCzhhOQh1D1/d473MHUl4/g0QUf NGLg== 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:content-transfer-encoding :in-reply-to:user-agent; bh=s/McZlVVjdxNyTIUHX9RRvYVGRo8R2JXZZfX3gG93e8=; b=JuJf/3+Erp5LZgRN1SqHBOjBb6vtXaF0j8VCVkcK7nxNMs7K1Rot72lR/ShmiUx4xd 1HEDHwyEUZaBiUwcW4H0ptvqaRF1EcYYw69jY3RG2pmWJxcJmzibKUiU6iS/krGT+dAT FDN6PHbC1LtU7KEkaUtD3qdICk9VHDRvs4ZicNRAfYqOditjCCQB8bl4kdlLTFgm6sH+ +c7Shk5/nfNh1XaAqHvW7tkg9oMtTbVzfsJXr297aQEH3O6S1ml7xwaw9sFq80sd9Pp+ Ps1Fov+KZQ1RV9Ep4vSr8VakWGevNe+3gu84OQoLZ0+hTjLVEqo/kiEXme3Snih1aYfv 6BrQ== X-Gm-Message-State: APjAAAWuu9/XnpzVDmzjUj/nbhRzM3i6QOZ7IbkfPk2kj99KA+ZwvvBT SIyNF4/mJkQp97UBUvUSJSH5Nw== X-Google-Smtp-Source: APXvYqz90dgAIXPLsXD8cBrfP05+GCTePquW249NBjBEx06BgXa1CCobvivpBorQec7jxt/iF9t2OQ== X-Received: by 2002:adf:dcc1:: with SMTP id x1mr4118047wrm.217.1571602722129; Sun, 20 Oct 2019 13:18:42 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id u68sm15621215wmu.12.2019.10.20.13.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2019 13:18:41 -0700 (PDT) Date: Sun, 20 Oct 2019 22:18:39 +0200 From: Tomas Vondra To: Andrew Dunstan Cc: "David G. Johnston" , Floris Van Nee , Ariadne Conill , Mark Felder , "pgsql-generallists.postgresql.org" , PostgreSQL Hackers Subject: Re: jsonb_set() strictness considered harmful to data Message-ID: <20191020201839.olpuyuzixagcvvud@development> References: <7dc242bd-b78f-2e0d-0c38-7b4b299f11bf@2ndQuadrant.com> <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: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Oct 20, 2019 at 03:48:05PM -0400, Andrew Dunstan wrote: > >On 10/20/19 1:14 PM, David G. Johnston wrote: >> On Sun, Oct 20, 2019 at 5:31 AM Andrew Dunstan >> > > wrote: >> >> And yet another is to >> raise an exception, which is easy to write but really punts the issue >> back to the application programmer who will have to decide how to >> ensure >> they never pass in a NULL parameter. >> >> >> That's kinda the point - if they never pass NULL they won't encounter >> any problems but as soon as the data and their application don't see >> eye-to-eye the application developer has to decide what they want to >> do about it.  We are in no position to decide for them and making it >> obvious they have a decision to make and implement here doesn't seem >> like a improper position to take. > > >The app dev can avoid this problem today by making sure they don't pass >a NULL as the value. Or they can use a wrapper function which does that >for them. So frankly this doesn't seem like much of an advance. And, as >has been noted, it's not consistent with what either MySQL or MSSQL do. >In general I'm not that keen on raising an exception for cases like this. > I think the general premise of this thread is that the application developer does not realize that may be necessary, because it's a bit surprising behavior, particularly when having more experience with other databases that behave differently. It's also pretty easy to not notice this issue for a long time, resulting in significant data loss. Let's say you're used to the MSSQL or MySQL behavior, you migrate your application to PostgreSQL or whatever - how do you find out about this behavior? Users are likely to visit https://www.postgresql.org/docs/12/functions-json.html but that says nothing about how jsonb_set works with NULL values :-( You're right raising an exception may not be the "right behavior" for whatever definition of "right". But I kinda agree with David that it's somewhat reasonable when we don't know what the "universally correct" thing is (or when there's no such thing). IMHO that's better than silently discarding some of the data. FWIW I think the JSON/JSONB part of our code base is amazing, and the fact that various other databases adopted something very similar over the last couple of years just confirms that. And if this is the only speck of dust in the API, I think that's pretty amazing. I'm not sure how significant this issue actually is - it's true we got a couple of complaints over the years (judging by a quick search for jsonb_set and NULL in the archives), but I'm not sure that's enough to justify any changes in backbranches. I'd say no, but I have no idea how many people are affected by this but don't know about it ... regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services