pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
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
Date: Tue, 09 Feb 2016 10:46:37 -0500
Message-ID: <8960.1455032797@sss.pgh.pa.us> (raw)
In-Reply-To: <20160208202959.2662.26227@wrigleys.postgresql.org>
References: <20160208202959.2662.26227@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (5+ messages)  latest in thread

Message-ID: <8960.1455032797@sss.pgh.pa.us>
Permalink:  ../8960.1455032797@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/8960.1455032797@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, xtracoder@gmail.com
  Subject: Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb
  In-Reply-To: <8960.1455032797@sss.pgh.pa.us>
  References: <20160208202959.2662.26227@wrigleys.postgresql.org> <8960.1455032797@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox