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 1hj1cs-0004bD-8s for pgsql-general@arkaria.postgresql.org; Thu, 04 Jul 2019 13:18: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 1hj1cr-000597-2F for pgsql-general@arkaria.postgresql.org; Thu, 04 Jul 2019 13:18:13 +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 1hj1cq-00054O-JW for pgsql-general@lists.postgresql.org; Thu, 04 Jul 2019 13:18:12 +0000 Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226] helo=blaine.gmane.org) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj1cn-00012S-O9 for pgsql-general@postgresql.org; Thu, 04 Jul 2019 13:18:11 +0000 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hj1cl-000O5y-Fh for pgsql-general@postgresql.org; Thu, 04 Jul 2019 15:18:07 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Thomas Kellerer Subject: Why does jsonb_set() remove non-mentioned keys? Date: Thu, 4 Jul 2019 15:18:01 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 X-Mozilla-News-Host: news://news.gmane.org:119 Content-Language: en-GB List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Why does select jsonb_set('{"foo": 1}'::jsonb, '{bar}', to_jsonb(null::int), true) return NULL when all it should do is to add a second key? I would expect {"foo": 1, "bar": null} or no change at all to the original JSON value, but not that the whole JSON is set to null. In the original case the new value to be set was the result of an expression, not a "hardcoded" null value. Thomas