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 1iM7aA-0005ep-HP for pgsql-general@arkaria.postgresql.org; Sun, 20 Oct 2019 09:33:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iM7a7-0003FA-Rk for pgsql-general@arkaria.postgresql.org; Sun, 20 Oct 2019 09:32:59 +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 1iM7a6-0002ZU-Ft for pgsql-general@lists.postgresql.org; Sun, 20 Oct 2019 09:32:59 +0000 Received: from mail.wordtothewise.com ([104.225.223.158]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1iM7H5-0004YO-6j for pgsql-general@lists.postgresql.org; Sun, 20 Oct 2019 09:13:24 +0000 Received: from [192.168.0.206] (unknown [37.228.251.105]) by mail.wordtothewise.com (Postfix) with ESMTPSA id 2B6529F147 for ; Sun, 20 Oct 2019 02:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wordtothewise.com; s=aardvark; t=1571562791; bh=LeXLEUmiACP3CrTiTTbVV5/CPa9SANub/rPNAKMzjLA=; h=Subject:To:References:From:Date:In-Reply-To:From; b=akmBC93xpyCbH5yheQ6uSz/5XXjnKng1RMPN55xmh8WfIMiG3iwyv9D4ufSGqfKfj 0fZzL4/GRo3UBfQxnyad3zpC/SmkQMd4qLvTA2IrtGiAQmckRjEdhDX/2paeUNHcgp +s+hDm2vdAo94iJD5oHGyZ+XWv0M8BGH09+gGlVo= Subject: Re: jsonb_set() strictness considered harmful to data To: pgsql-general@lists.postgresql.org References: <20191018215018.GB56427@elch.exwg.net> <7299c63c-fcdc-20fc-c955-4cd330cc4580@aklaver.com> From: Steve Atkins Message-ID: <5d3488c4-fd04-ee99-fb1e-e88cdb485238@blighty.com> Date: Sun, 20 Oct 2019 10:13:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 19/10/2019 07:52, Ariadne Conill wrote: > > I would say that any thing like > > update whatever set column=jsonb_set(column, '{foo}', NULL) > > should throw an exception. It should do, literally, *anything* else > but blank that column. steve=# create table foo (bar jsonb not null); CREATE TABLE steve=# insert into foo (bar) values ('{"a":"b"}'); INSERT 0 1 steve=# update foo set bar = jsonb_set(bar, '{foo}', NULL); ERROR:  null value in column "bar" violates not-null constraint DETAIL:  Failing row contains (null). steve=# update foo set bar = jsonb_set(bar, '{foo}', 'null'::jsonb); UPDATE 1 I don't see any behaviour that's particularly surprising there? Though I understand how an app developer who's light on SQL might get it wrong - and I've made similar mistakes in schema upgrade scripts without involving jsonb. Cheers,   Steve