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 1iNjYg-0003iv-5c for pgsql-general@arkaria.postgresql.org; Thu, 24 Oct 2019 20:18:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iNjYd-0004Vb-Vn for pgsql-general@arkaria.postgresql.org; Thu, 24 Oct 2019 20:18:07 +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 1iNjYd-0004VU-MY for pgsql-general@lists.postgresql.org; Thu, 24 Oct 2019 20:18:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNjYa-0004p6-LG for pgsql-general@lists.postgresql.org; Thu, 24 Oct 2019 20:18:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x9OKHwY9020074; Thu, 24 Oct 2019 16:17:58 -0400 From: Tom Lane To: Laurenz Albe cc: Stuart McGraw , "pgsql-generallists.postgresql.org" Subject: Re: jsonb_set() strictness considered harmful to data In-reply-to: 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> <20191022225513.GA12201@hjp.at> <04cf2b8a-1673-9060-5bd0-dce3e07ee11d@mtneva.com> Comments: In-reply-to Laurenz Albe message dated "Thu, 24 Oct 2019 21:15:42 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20072.1571948278.1@sss.pgh.pa.us> Date: Thu, 24 Oct 2019 16:17:58 -0400 Message-ID: <20073.1571948278@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Laurenz Albe writes: > On Wed, 2019-10-23 at 13:00 -0600, Stuart McGraw wrote: >> It is less sensible with compound values where the rule can apply to >> individual scalar components. I agree that JSON can sensibly be viewed as a composite value, but ... >> And indeed that is what Postgresql does >> for another compound type: >> >> # select array_replace(array[1,2,3],2,NULL); >> array_replace >> --------------- >> {1,NULL,3} >> >> The returned value is not NULL. Why the inconsistency between the array >> type and json type? ... the flaw in this argument is that the array element is actually a SQL NULL when we're done. To do something similar in the JSON case, we have to translate SQL NULL to JSON null, and that's cheating to some extent. They're not the same thing (and I'll generally resist proposals to, say, make SELECT 'null'::json IS NULL return true). Maybe it's okay to make this case work like that, but don't be too high and mighty about it being logically clean; it isn't. regards, tom lane