Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aTAV1-0001aI-VL for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Feb 2016 15:46:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aTAV0-0003Lg-Py for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Feb 2016 15:46:42 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aTAV0-0003LZ-8k for pgsql-bugs@postgresql.org; Tue, 09 Feb 2016 15:46:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aTAUx-0005iG-QG for pgsql-bugs@postgresql.org; Tue, 09 Feb 2016 15:46:40 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u19FkbO4008961; Tue, 9 Feb 2016 10:46:37 -0500 From: Tom Lane To: xtracoder@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb In-reply-to: <20160208202959.2662.26227@wrigleys.postgresql.org> References: <20160208202959.2662.26227@wrigleys.postgresql.org> Comments: In-reply-to xtracoder@gmail.com message dated "Mon, 08 Feb 2016 20:29:59 +0000" Date: Tue, 09 Feb 2016 10:46:37 -0500 Message-ID: <8960.1455032797@sss.pgh.pa.us> X-Pg-Spam-Score: -2.2 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs