From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | xtracoder(at)gmail(dot)com |
Cc: | 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 15:46:37 |
Message-ID: | 8960.1455032797@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
xtracoder(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2016-02-09 15:55:40 | Re: BUG #13934: wrong result of split_part with char value |
Previous Message | Joe Conway | 2016-02-09 15:29:08 | Re: BUG #13934: wrong result of split_part with char value |