From: rainer.steinmueller@kit.edu
To: pgsql-bugs@postgresql.org
Subject: BUG #14449: inconsistency in behaviour of json/jsonb returning functions for sql NULL and json NULL values
Date: Mon, 05 Dec 2016 17:53:54 +0000
Message-ID: <20161205175354.4360.29511@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 14449
Logged by: Rainer Steinmüller
Email address: rainer.steinmueller@kit.edu
PostgreSQL version: 9.6.1
Operating system: Debian 3.16.36-1+deb8u2 x86_64 GNU/Linux
Description:
# all the following sql statements are tested with psql.
# try to cast or to convert a sql NULL value to json/jsonb null does not
generate the desired result:
net=> select to_jsonb(null::text);
to_jsonb
----------
(1 row)
# this is the correct result:
net=> select jsonb_build_object('f1', null) -> 'f1';
?column?
----------
null
(1 row)
# the same behaviour for manipulating jsonb:
# this statement does not generate the desired result and worst, it destroys
the whole jsonb data:
net=> select jsonb_set('{"f1":1,"f2":"abc"}', '{f1}', null);
jsonb_set
-----------
(1 row)
# the following does well (but works only for jsonb due to the ||
operator):
net=> select '{"f1":1,"f2":"abc"}'::jsonb || jsonb_build_object('f1',
null);
?column?
---------------------------
{"f1": null, "f2": "abc"}
(1 row)
# problem: how to set a jsonb null value over more than 1 level (the path
array in arg2 has more than 1 element) like this:
# select jsonb_set('{"f1":1,"f2":"abc","f3": {}}', '{f3,f4}', null);
# in my opinion, json/jsonb returning functions
# to_json(), to_jsonb(), jsonb_set(), jsonb_insert()
# should never return sql null values if they receive a sql null argument
(as value that is to convert implicitly).
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: rainer.steinmueller@kit.edu
Subject: Re: BUG #14449: inconsistency in behaviour of json/jsonb returning functions for sql NULL and json NULL values
In-Reply-To: <20161205175354.4360.29511@wrigleys.postgresql.org>
References: <20161205175354.4360.29511@wrigleys.postgresql.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