pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general@postgresql.org
Subject: Re: Why does jsonb_set() remove non-mentioned keys?
Date: Thu, 4 Jul 2019 22:33:12 +0200
Message-ID: <qflnq9$86re$1@blaine.gmane.org> (raw)
In-Reply-To: <CAKFQuwaEErw0+DH6w+XwzbSMYiWdcRO5Bcy2ts_1C6FTB0TxMw@mail.gmail.com>
References: <qfkua9$2q0e$1@blaine.gmane.org>
	<CAKFQuwaEErw0+DH6w+XwzbSMYiWdcRO5Bcy2ts_1C6FTB0TxMw@mail.gmail.com>

David G. Johnston schrieb am 04.07.2019 um 18:20:
> On Thu, Jul 4, 2019 at 6:18 AM Thomas Kellerer <spam_eater@gmx.net <mailto:spam_eater@gmx.net>> wrote:
> 
>     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?
> 
> 
> Both functions involved are defined as being STRICT (null on null
> input).  You need to COALSESCE SQL NULL to JSON 'null' to obtain the
> result you desire.  This is a general truth when dealing with the
> JSON type in PostgreSQL.

But jsonb_set() doesn't change (or shouldn't) the whole value, only one key.

I can understand that the "bar" key would not be set (because of the NULL), but removing a key that isn't even part of the target path looks like a bug to.

Thomas

  






view thread (9+ messages)  latest in thread

Message-ID: <qflnq9$86re$1@blaine.gmane.org>
Permalink:  ../qflnq9$86re$1@blaine.gmane.org/
Also on:    postgresql.org/message-id/qflnq9$86re$1@blaine.gmane.org

 · 

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: spam_eater@gmx.net
  Subject: Re: Why does jsonb_set() remove non-mentioned keys?
  In-Reply-To: <qflnq9$86re$1@blaine.gmane.org>
  References: <qfkua9$2q0e$1@blaine.gmane.org> <CAKFQuwaEErw0+DH6w+XwzbSMYiWdcRO5Bcy2ts_1C6FTB0TxMw@mail.gmail.com> <qflnq9$86re$1@blaine.gmane.org>

* 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