BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb

From: xtracoder(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb
Date: 2016-02-08 20:29:59
Message-ID: 20160208202959.2662.26227@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 13937
Logged by: Xtra Coder
Email address: xtracoder(at)gmail(dot)com
PostgreSQL version: 9.5.0
Operating system: Windows7
Description:

Steps to reproduce:
-------------------

DO LANGUAGE plpgsql $$
DECLARE
jsonb_src jsonb;
jsonb_dst jsonb;
BEGIN
jsonb_src = '{
"key1": {"data1": [1, 2, 3]},
"key2": {"data2": [3, 4, 5]}
}';
raise notice 'jsonb_src = %', jsonb_src;

with t_data as (select * from jsonb_each(jsonb_src))
select jsonb_object(
array(select key from t_data),
array(select value::text from t_data) )
into jsonb_dst;
raise notice 'jsonb_dst = %', jsonb_dst;
END $$;

Actual result:
--------------

NOTICE: jsonb_src = {"key1": {"data1": [1, 2, 3]}, "key2": {"data2": [3, 4,
5]}}
NOTICE: jsonb_dst = {"key1": "{\"data1\": [1, 2, 3]}", "key2": "{\"data2\":
[3, 4, 5]}"}

What's wrong? - values in 'dst' are represented as text. Reason -
jsonb_object() has arguments as jsonb_object(keys text[], values text[]) and
there is no way to pass values as 'jsonb'. Conversion to 'text' looses JSON
structure.

Expected result:
----------------

NOTICE: jsonb_src = {"key1": {"data1": [1, 2, 3]}, "key2": {"data2": [3, 4,
5]}}
NOTICE: jsonb_dst = {"key1": {"data1": [1, 2, 3]}, "key2": {"data2": [3, 4,
5]}}

'src' and 'dst' JSON objects should be identical/equal.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2016-02-09 00:07:34 Re: Re: BUG #13685: Archiving while idle every archive_timeout with wal_level hot_standby
Previous Message xtracoder 2016-02-08 19:52:07 BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container