From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | "xtracoder(at)gmail(dot)com" <xtracoder(at)gmail(dot)com> |
Cc: | "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org> |
Subject: | Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb |
Date: | 2016-02-09 02:23:52 |
Message-ID: | CAKFQuwbFM2VEwMgQZFWOTg9GLkMc0AQeLW_iBHx+JQXyqc8L9g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Monday, February 8, 2016, <xtracoder(at)gmail(dot)com> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 13937
> Logged by: Xtra Coder
> Email address: xtracoder(at)gmail(dot)com <javascript:;>
> 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.
>
>
While I see the value of your species behavior there is no explicit promise
to evaluate the provided text for json-ness and convert it. This is also
not going to change now that it has been released. New functions would be
needed that would enable round-tripping of json in the manner you describe.
Someone else may have advice regarding a work-around until someone commits
such capabilities into a future release.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2016-02-09 02:45:56 | Re: BUG #13918: Simple query with Having clause returns incorrect results |
Previous Message | David G. Johnston | 2016-02-09 02:00:52 | Re: BUG #13934: wrong result of split_part with char value |