Re: Fwd: JSONB order?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Tony Shelver <tshelver(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: JSONB order?
Date: 2020-11-05 16:57:53
Message-ID: bee2374f-9005-20bc-22e4-8214cbde1627@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/5/20 7:45 AM, Tony Shelver wrote:
>
>
> ---------- Forwarded message ---------
> From: *Tony Shelver* <tshelver(at)gmail(dot)com <mailto:tshelver(at)gmail(dot)com>>
> Date: Thu, 5 Nov 2020 at 17:45
> Subject: Re: JSONB order?
> To: Christophe Pettus <xof(at)thebuild(dot)com <mailto:xof(at)thebuild(dot)com>>
>
>
> Thanks Christophe, that's what I thought.
> Just seemed weird that they were 'disordered' in exactly the same way
> every time.

Probably because that resolves to the most efficient way to store in
jsonb for that particular record.

>
> FYI, as of Python 3.7, dicts /_are_/ ordered.

By insertion order so updating a dict with a new item will add new key
to end.

>
> The problem is that we are possibly going to have many versions of these
> forms with slightly differing keys, which will be a pain to order in
> some hard coded way.
>
>
>
> On Thu, 5 Nov 2020 at 17:40, Christophe Pettus <xof(at)thebuild(dot)com
> <mailto:xof(at)thebuild(dot)com>> wrote:
>
>
>
> > On Nov 5, 2020, at 07:34, Tony Shelver <tshelver(at)gmail(dot)com
> <mailto:tshelver(at)gmail(dot)com>> wrote:
> > But...  seen above, the order gets mixed up.
> >
> > Any ideas?
>
> JSON objects, like Python dicts, are not automatically ordered by
> key.  Once you move from the column space to the JSON object space,
> you can't rely on the object keys being in a consistent order.
>
> You'll want to have a step when ingesting the JSON object into a
> report that lines up the key values appropriately with the right
> presentation in the report.
> --
> -- Christophe Pettus
> xof(at)thebuild(dot)com <mailto:xof(at)thebuild(dot)com>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dmitry O Litvintsev 2020-11-05 19:03:54 how to check that recovery is complete
Previous Message Raphaël Enrici 2020-11-05 16:51:31 Diagnose memory leak in logical replication?