Why does jsonb_set() remove non-mentioned keys?

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Why does jsonb_set() remove non-mentioned keys?
Date: 2019-07-04 13:18:01
Message-ID: qfkua9$2q0e$1@blaine.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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?

I would expect {"foo": 1, "bar": null} or no change at all to the original JSON value, but not that the whole JSON is set to null.

In the original case the new value to be set was the result of an expression, not a "hardcoded" null value.

Thomas

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-07-04 14:38:42 Re: Error: rows returned by function are not all of the same row type
Previous Message Andrey Sychev 2019-07-04 12:20:46 Error: rows returned by function are not all of the same row type