Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb
От | Tom Lane |
---|---|
Тема | Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb |
Дата | |
Msg-id | 8960.1455032797@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb (xtracoder@gmail.com) |
Ответы |
Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() ->
'dst' does not recreate 'src' as valid jsonb
|
Список | pgsql-bugs |
xtracoder@gmail.com writes: > 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. Considering that you explicitly casted the "values" to text, it would absolutely be a bug if you got that result from this code. I don't think this is a bug at all; it's a feature request for some new variant of jsonb_object(). But can't you already get what you want from jsonb_object_agg()? 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_agg(key, value) into jsonb_dst from t_data; raise notice 'jsonb_dst = %', jsonb_dst; END $$; 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]}} DO I think your original coding is kinda broken anyway; there's no hard guarantee that those two array sub-selects will give results in the same order. regards, tom lane
В списке pgsql-bugs по дате отправления: