Re: Better way to sort a JSONB array?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Michael Moore <michaeljmoore(at)gmail(dot)com>
Cc: postgres list <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Better way to sort a JSONB array?
Date: 2017-08-07 22:04:49
Message-ID: CAKFQuwYPf1oQV0tK-=WMev=1seUn_nWZDV74WOgApoN2YqLjLA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Aug 7, 2017 at 2:53 PM, Michael Moore <michaeljmoore(at)gmail(dot)com>
wrote:

> Hi David,
> Maybe there isn't a less verbose way. It just seems like a bit much that I
> have to take the jsonb array, convert it into a relation so that SELECT can
> operate on it, only so that I can sort it, and then convert it back into a
> jsonb array object. I was hoping for something like
> json_table2.aggSort("portal_name"). I'm not actually using json_table2 as
> a name, that was just for my minimalist example. As mentioned, my real
> project consists of refactoring a pgsql function which uses TEMP tables to
> NOT use temp tables, but instead, JSONB objects.
>
>
​PostgreSQL is closer to "pure function​al" than "object oriented" if that
helps explain things. We do a thorough job of documenting the functions we
do have and a quick skim of the json related functions does not reveal any
with a signature like: jsonb_sort(array_of_objects_json_array_value jsonb,
top_level_object_key_name__or_path text). You might want to post that as a
feature request on -general and see what others more familiar with the json
implementation think about the idea - we have jsonb_set and jsonb_insert so
the request isn't completely novel - but as it stands today the whole
"dis-assemble->act->re-assemble" flow is the one that we are stuck with.

David J.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Moore 2017-08-07 22:10:26 Re: Better way to sort a JSONB array?
Previous Message Michael Moore 2017-08-07 21:53:35 Re: Better way to sort a JSONB array?