pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: Why does jsonb_set() remove non-mentioned keys?
Date: Fri, 5 Jul 2019 13:50:01 +0200
Message-ID: <20190705115001.3xjrsonpkuioujgl@hjp.at> (raw)
In-Reply-To: <e71033e4-eadf-5235-cc1b-9c54b7bd827c@gmx.net>
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>
	<e71033e4-eadf-5235-cc1b-9c54b7bd827c@gmx.net>

On 2019-07-05 10:59:31 +0200, Thomas Kellerer wrote:
> Gianni Ceccarelli schrieb am 05.07.2019 um 10:00:
> >> 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`
> > 
> 
> Ah, I see. Thanks for the clarification
> 
> Then I would question if declaring jsonb_set as "strict" makes sense

I think it does but I raise the same question for to_jsonb. It's defined
on anyelement and the documentation says:

| Returns the value as json or jsonb. Arrays and composites are converted
| (recursively) to arrays and objects; otherwise, if there is a cast from
| the type to json, the cast function will be used to perform the
| conversion; otherwise, a scalar value is produced. For any scalar type
| other than a number, a Boolean, or a null value, the text representation
| will be used, in such a fashion that it is a valid json or jsonb value.

The documentation explicitely singles out "a number, a Boolean, or a
null value", but doesn't specify how they are treated. I would expect
that they are treated equivalently, though: An SQL number is converted
to a JSON number, an SQL boolean is converted to JSON true or false and
an SQL null is converted to JSON null. Returning SQL null instead of a
JSON null breaks that expectation for no discernible reason. It also
isn't consistent, since an SQL null in an array or composite is
converted to a JSON null, as I would expect.

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/;

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (9+ messages)

Message-ID: <20190705115001.3xjrsonpkuioujgl@hjp.at>
Permalink:  ../20190705115001.3xjrsonpkuioujgl@hjp.at/
Also on:    postgresql.org/message-id/20190705115001.3xjrsonpkuioujgl@hjp.at

 · 

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: hjp-pgsql@hjp.at
  Subject: Re: Why does jsonb_set() remove non-mentioned keys?
  In-Reply-To: <20190705115001.3xjrsonpkuioujgl@hjp.at>
  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> <e71033e4-eadf-5235-cc1b-9c54b7bd827c@gmx.net> <20190705115001.3xjrsonpkuioujgl@hjp.at>

* 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