pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14449: inconsistency in behaviour of json/jsonb returning functions for sql NULL and json NULL values
2+ messages / 2 participants
[nested] [flat]

* BUG #14449: inconsistency in behaviour of json/jsonb returning functions for sql NULL and json NULL values
@ 2016-12-05 17:53 rainer.steinmueller@kit.edu
  2016-12-05 18:30 ` Re: BUG #14449: inconsistency in behaviour of json/jsonb returning functions for sql NULL and json NULL values David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: rainer.steinmueller@kit.edu @ 2016-12-05 17:53 UTC (permalink / raw)
  To: pgsql-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


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #14449: inconsistency in behaviour of json/jsonb returning functions for sql NULL and json NULL values
  2016-12-05 17:53 BUG #14449: inconsistency in behaviour of json/jsonb returning functions for sql NULL and json NULL values rainer.steinmueller@kit.edu
@ 2016-12-05 18:30 ` David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2016-12-05 18:30 UTC (permalink / raw)
  To: rainer.steinmueller@kit.edu; +Cc: pgsql-bugs

On Mon, Dec 5, 2016 at 10:53 AM, <rainer.steinmueller@kit.edu> wrote:

> 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)
>

​Previous discussion on -hackers on this topic.

https://www.postgresql.org/message-id/CAFj8pRBdi4Ud-%3D8kfM28i7fa%3DB6t%3DnFTM3UK5qNBm9TjazC99A%40ma...

​The general conclusion is that the benefit of making this consistent
outweighs the effort to define that consistency and introduce a breakage in
compatibility.​

David J.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2016-12-05 18:30 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-12-05 17:53 BUG #14449: inconsistency in behaviour of json/jsonb returning functions for sql NULL and json NULL values rainer.steinmueller@kit.edu
2016-12-05 18:30 ` David G. Johnston <david.g.johnston@gmail.com>

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