Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb
От | David G. Johnston |
---|---|
Тема | Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb |
Дата | |
Msg-id | CAKFQuwbFM2VEwMgQZFWOTg9GLkMc0AQeLW_iBHx+JQXyqc8L9g@mail.gmail.com обсуждение исходный текст |
Ответ на | BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb (xtracoder@gmail.com) |
Список | pgsql-bugs |
On Monday, February 8, 2016, <xtracoder@gmail.com> wrote: > The following bug has been logged on the website: > > Bug reference: 13937 > Logged by: Xtra Coder > Email address: xtracoder@gmail.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.
В списке pgsql-bugs по дате отправления: