Re: general purpose array_sort

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

From: "David G. Johnston" <david.g.johnston@gmail.com>
To: Junwang Zhao <zhjwpku@gmail.com>
Cc: jian he <jian.universality@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, "andreas@proxel.se" <andreas@proxel.se>, Robert Haas <robertmhaas@gmail.com>, Amit Langote <amitlangote09@gmail.com>
Date: 2024-09-29T02:50:38Z
Lists: pgsql-hackers
On Sat, Sep 28, 2024 at 7:05 PM Junwang Zhao <zhjwpku@gmail.com> wrote:

> On Sat, Sep 28, 2024 at 10:41 PM jian he <jian.universality@gmail.com>
> wrote:
> >
> > <parameter>dir</parameter> can have only two potential values, make it
> > as a boolean would be more easier?
> > you didn't mention information:  "by default, it will sort by
> > ascending order; the sort collation by default is using the array
> > element type's collation"
> >
> > tuplesort_begin_datum can do null-first, null-last, so the
> > one-dimension array can allow null values.
>
> The following(create extension intarry first) will give an error, I
> keep the same for array_sort.
>
> SELECT sort('{1234234,-30,234234, null}');
>
>
I would suggest accepting:
asc
desc
asc nulls first
asc nulls last *
desc nulls first *
desc nulls last

As valid inputs for "dir" - and that the starred options are the defaults
when null position is omitted.

In short, mimic create index.

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__.