Re: general purpose array_sort

Dean Rasheed <dean.a.rasheed@gmail.com>

From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: Junwang Zhao <zhjwpku@gmail.com>
Cc: Aleksander Alekseev <aleksander@timescale.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Tom Lane <tgl@sss.pgh.pa.us>, "David G. Johnston" <david.g.johnston@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-11-04T11:33:51Z
Lists: pgsql-hackers
On Sun, 3 Nov 2024 at 03:33, Junwang Zhao <zhjwpku@gmail.com> wrote:
>
> PFA v11.
>

Testing this with an array with non-default lower bounds, it fails to
preserve the array bounds, which I think it should (note:
array_reverse() and array_shuffle() do preserve the bounds):

SELECT array_reverse(a), array_shuffle(a), array_sort(a)
  FROM (VALUES ('[10:12][20:21]={{1,2},{10,20},{3,4}}'::int[])) v(a);

-[ RECORD 1 ]-+-------------------------------------
array_reverse | [10:12][20:21]={{3,4},{10,20},{1,2}}
array_shuffle | [10:12][20:21]={{10,20},{3,4},{1,2}}
array_sort    | [1:3][20:21]={{1,2},{3,4},{10,20}}

Regards,
Dean



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