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 1hjJ9Q-0001CN-CF for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 08:01:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hjJ9P-0002Bm-0f for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 08:00: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 1hjJ9O-0001x3-H2 for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2019 08:00:58 +0000 Received: from mail.thenautilus.net ([5.79.87.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hjJ9H-0002Ks-6w for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2019 08:00:57 +0000 Received: (qmail 29690 invoked from network); 5 Jul 2019 08:00:47 -0000 Received: from unknown (HELO nautilus) (dakkar@81.2.107.215) by 0 with ESMTPA; 5 Jul 2019 08:00:47 -0000 Date: Fri, 5 Jul 2019 09:00:47 +0100 From: Gianni Ceccarelli To: pgsql-general@lists.postgresql.org Subject: Re: Why does jsonb_set() remove non-mentioned keys? Message-ID: <20190705090047.41600de5@nautilus> In-Reply-To: References: <20190704220350.514a15a5@thenautilus.net> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Aha! I had mis-understood how "strict"-ness works. Thank you David for the explanation! Thomas: the two main pieces are these: > SQL null and json null are represented differently As far as SQL is concerned, `'null'::jsonb` is a valid (non-`NULL`) value. The SQL part of Postgres doesn't "look inside" the jsonb value, the same way it doesn't "look inside" numbers or strings or whatever. It only cares if they're `NULL` or not, and then it passes them to functions and operators (ok, it does look at boolean values for `WHERE` clauses, but even `ORDER BY` is handled by comparison operators) > strict functions with sql null inputs yield sql null output without > even executing the function So when the SQL-level executor sees a call to any function declared strict with some NULL parameters, it doesn't call the function at all. `whatever_my_function('a string',1234,NULL)` is always `NULL` -- Dakkar - GPG public key fingerprint = A071 E618 DD2C 5901 9574 6FE2 40EA 9883 7519 3F88 key id = 0x75193F88