Re: BUG #14178: output of jsonb_object and json_object doesn't match textually

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: ap(at)zip(dot)com(dot)au, PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14178: output of jsonb_object and json_object doesn't match textually
Date: 2016-06-08 02:59:10
Message-ID: CAB7nPqReds5Hf+_Sd=sLT5D59AHnifg18QTWTe--Wh=fqzaqsg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Jun 7, 2016 at 8:58 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> OK, that would make the entries generated a bit more compact.. Are
> there other opinions on the matter?

I have noticed as well that array elements separated by a comma use a
space after the comma with jsonb, and not with json. Still, doing
improvements in this area would be useful if a user is interested in
doing direct comparison of jsonb with json after casting them into
text to save some parsing cost. Still, an area where things are not
under controll with json is the key ordering within the same nest
level, which is on the contrary pre-defined in jsonb by the unicity of
the key names, and that's not the case of json. Take this example:

=# select row_to_json(r)::json from ( select relkind, oid::regclass as
name from pg_class where relname = 'pg_class') r;
row_to_json
------------------------------------
{"relkind":"r", "name":"pg_class"}
(1 row)
=# select row_to_json(r)::jsonb from (select relkind, oid::regclass as
name from pg_class where relname = 'pg_class') r;
row_to_json
--------------------------------------
{"name": "pg_class", "relkind": "r"}
(1 row)
This kills any hope of comparison.

So after thinking more on the matter, I'd rather give up on such
patches and recommend doing ::jsonb::text to be able to do equality
comparisons. If you want to get output similar to what jsonb is doing,
a simple cast with ::jsonb looks rather the saner way to go. This
induces more parsing cost, but that's the cost to pay...
--
Michael

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2016-06-08 03:04:05 Re: [BUGS] Routine analyze of single column prevents standard autoanalyze from running at all
Previous Message Michael Paquier 2016-06-08 02:07:28 Re: [BUGS] BUG #14155: bloom index error with unlogged table