pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gianni Ceccarelli <dakkar@thenautilus.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Why does jsonb_set() remove non-mentioned keys?
Date: Fri, 5 Jul 2019 09:00:47 +0100
Message-ID: <20190705090047.41600de5@nautilus> (raw)
In-Reply-To: <CAKFQuwbb7=ciX-MXeDyAk1H4WFNQZXpQh82eby8ExY4epYT0gQ@mail.gmail.com>
References: <qfkua9$2q0e$1@blaine.gmane.org>
	<CAKFQuwaEErw0+DH6w+XwzbSMYiWdcRO5Bcy2ts_1C6FTB0TxMw@mail.gmail.com>
	<qflnq9$86re$1@blaine.gmane.org>
	<20190704220350.514a15a5@thenautilus.net>
	<CAKFQuwbb7=ciX-MXeDyAk1H4WFNQZXpQh82eby8ExY4epYT0gQ@mail.gmail.com>

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 - <Mobilis in mobile>
	GPG public key fingerprint = A071 E618 DD2C 5901 9574
	                             6FE2 40EA 9883 7519 3F88
	                    key id = 0x75193F88





view thread (9+ messages)  latest in thread

Message-ID: <20190705090047.41600de5@nautilus>
Permalink:  ../20190705090047.41600de5@nautilus/
Also on:    postgresql.org/message-id/20190705090047.41600de5@nautilus

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: dakkar@thenautilus.net
  Subject: Re: Why does jsonb_set() remove non-mentioned keys?
  In-Reply-To: <20190705090047.41600de5@nautilus>
  References: <qfkua9$2q0e$1@blaine.gmane.org> <CAKFQuwaEErw0+DH6w+XwzbSMYiWdcRO5Bcy2ts_1C6FTB0TxMw@mail.gmail.com> <qflnq9$86re$1@blaine.gmane.org> <20190704220350.514a15a5@thenautilus.net> <CAKFQuwbb7=ciX-MXeDyAk1H4WFNQZXpQh82eby8ExY4epYT0gQ@mail.gmail.com> <20190705090047.41600de5@nautilus>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox