From: AP <ap@zip.com.au>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14178: output of jsonb_object and json_object doesn't match textually
Date: Wed, 8 Jun 2016 20:32:41 +1000
Message-ID: <20160608103241.GE18838@zip.com.au> (raw)
In-Reply-To: <CAB7nPqReds5Hf+_Sd=sLT5D59AHnifg18QTWTe--Wh=fqzaqsg@mail.gmail.com>
References: <20160607014234.1381.95994@wrigleys.postgresql.org>
<CAB7nPqSneeh7NPhWM9zU3bEf9nY4N9hWTf9D_2Pj031OA6VH3Q@mail.gmail.com>
<CAEepm=0XMz1_Hy1twpsTd+2suQVrsCecjuWuAUYfdswWKQfG2g@mail.gmail.com>
<CAB7nPqRrdJeRcTGv+64xLZuGfVo9xvQyv+zu0_96SALiFrP=5g@mail.gmail.com>
<CAEepm=09NJt4-NAm9Z6j9fVOGh9nFqHJ852SoJf_dhq3eBeduw@mail.gmail.com>
<CAB7nPqQOuV+snOhWCF3enzYVv+66hWCo5ZGjBx1jd14Kb5-EwQ@mail.gmail.com>
<CAB7nPqReds5Hf+_Sd=sLT5D59AHnifg18QTWTe--Wh=fqzaqsg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Wed, Jun 08, 2016 at 11:59:10AM +0900, Michael Paquier wrote:
> 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...
I think two things are being somewhat conflated:
1. the look of our JSON structures - we should be consistent here
2. the ordering of our JSON structures internally - a related (for the above
use case issue) but, ultimately, seperate issue.
1 is easy to solve. JSON is JSON is JSON whether it's in a JSON data-type or
JSONB and so no matter which it should look the same.
The types JSON and JSONB, to my knowledge, are different in terms of
internal (wrt postgres) representation and what they promise:
"Because the json type stores an exact copy of the input text, it will
preserve semantically-insignificant white space between tokens, as well as
the order of keys within JSON objects. Also, if a JSON object within the
value contains the same key more than once, all the key/value pairs are
kept. (The processing functions consider the last value as the operative
one.) By contrast, jsonb does not preserve white space, does not preserve
the order of object keys, and does not keep duplicate object keys. If
duplicate keys are specified in the input, only the last value is kept."
- https://www.postgresql.org/docs/current/static/datatype-json.html
As you can see, the key ordering is already covered. If you care, stick to JSON.
If you don't, fly JSONB airlines.
I think it's still worth doing #1 above and I'm willing to do the patch
myself (it didn't occur to me how simple it was and I've been kicking myself
at losing the opportunity to contribute :( :) ) if need be and if it'll fly.
Andrew
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: ap@zip.com.au, michael.paquier@gmail.com, thomas.munro@enterprisedb.com
Subject: Re: BUG #14178: output of jsonb_object and json_object doesn't match textually
In-Reply-To: <20160608103241.GE18838@zip.com.au>
References: <20160607014234.1381.95994@wrigleys.postgresql.org> <CAB7nPqSneeh7NPhWM9zU3bEf9nY4N9hWTf9D_2Pj031OA6VH3Q@mail.gmail.com> <CAEepm=0XMz1_Hy1twpsTd+2suQVrsCecjuWuAUYfdswWKQfG2g@mail.gmail.com> <CAB7nPqRrdJeRcTGv+64xLZuGfVo9xvQyv+zu0_96SALiFrP=5g@mail.gmail.com> <CAEepm=09NJt4-NAm9Z6j9fVOGh9nFqHJ852SoJf_dhq3eBeduw@mail.gmail.com> <CAB7nPqQOuV+snOhWCF3enzYVv+66hWCo5ZGjBx1jd14Kb5-EwQ@mail.gmail.com> <CAB7nPqReds5Hf+_Sd=sLT5D59AHnifg18QTWTe--Wh=fqzaqsg@mail.gmail.com> <20160608103241.GE18838@zip.com.au>
* 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