From: Michael Paquier <michael@paquier.xyz>
To: claudel.sylvain@gmail.com
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15075: jsonb_set return [null] if new value is null but not 'null'.
Date: Mon, 19 Feb 2018 18:18:23 +0900
Message-ID: <20180219091823.GA42340@paquier.xyz> (raw)
In-Reply-To: <151902922995.1388.15352428607143555614@wrigleys.postgresql.org>
References: <151902922995.1388.15352428607143555614@wrigleys.postgresql.org>
On Mon, Feb 19, 2018 at 08:33:49AM +0000, PG Bug reporting form wrote:
> Is this behavior normal ?
>
> select jsonb_set('{"f1":1,"f2":null,"f3":"bidule"}', '{f3}', null, false);
> #> [null]
> select jsonb_set('{"f1":1,"f2":null,"f3":"bidule"}', '{f3}', 'null',
> false);
> #> {"f1":1,"f2":null,"f3":null}
>
> In a update query, it is dangerous.
> It may be better that the request crashes rather than executing with
> surprising behavior.
jsonb_set is a strict function, meaning that any NULL value from input
arguments will make the function return NULL as result, which is what
your first example does. In the second query, you are using null as
JSON value, which is actually valid as input. So as far as I can see,
this is normal.
> Sorry if this report is not "clean".
No problem. I have been able to decrypt it easily :)
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
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-bugs@postgresql.org
Cc: michael@paquier.xyz, claudel.sylvain@gmail.com
Subject: Re: BUG #15075: jsonb_set return [null] if new value is null but not 'null'.
In-Reply-To: <20180219091823.GA42340@paquier.xyz>
References: <151902922995.1388.15352428607143555614@wrigleys.postgresql.org> <20180219091823.GA42340@paquier.xyz>
* 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