Re: general purpose array_sort

David G. Johnston <david.g.johnston@gmail.com>

From: "David G. Johnston" <david.g.johnston@gmail.com>
To: Aleksander Alekseev <aleksander@timescale.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Tom Lane <tgl@sss.pgh.pa.us>, Junwang Zhao <zhjwpku@gmail.com>, jian he <jian.universality@gmail.com>, Amit Langote <amitlangote09@gmail.com>, "andreas@proxel.se" <andreas@proxel.se>, Robert Haas <robertmhaas@gmail.com>
Date: 2024-10-24T15:11:33Z
Lists: pgsql-hackers
On Thu, Oct 24, 2024 at 7:58 AM Aleksander Alekseev <
aleksander@timescale.com> wrote:

> Hi,
>
> > It's hardly "general purpose" if it randomly refuses to
> > sort certain types.  I would say it should be able to sort
> > anything that ORDER BY will handle --- and that certainly
> > includes the cases shown here.
>
> I wonder how useful / convenient the new function will be considering
> that we already have CTEs and can do:
>
> SELECT array_agg(x ORDER BY x) FROM unnest(ARRAY[5,1,3,2,4]) AS x;
>
> Perhaps there are use cases I didn't consider?
>
>
Succinctness of expression.  Plus I'm under the impression that a function
doing this is going to be somewhat faster than composing two functions
together within a multi-node subtree.

I feel like the same observation could have been made for array_shuffle but
we added that.  This function being added feels to me like just completing
the set.

David J.

Commits

  1. Introduce a SQL-callable function array_sort(anyarray).

  2. Fix ARRAY_SUBLINK and ARRAY[] for int2vector and oidvector input.

  3. Re-implement the ereport() macro using __VA_ARGS__.