Re: general purpose array_sort

Robert Haas <robertmhaas@gmail.com>

From: Robert Haas <robertmhaas@gmail.com>
To: Junwang Zhao <zhjwpku@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>, 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>
Date: 2024-11-07T14:29:05Z
Lists: pgsql-hackers
On Thu, Nov 7, 2024 at 8:56 AM Junwang Zhao <zhjwpku@gmail.com> wrote:
> Yeah, this is reasonable but one case I can't be sure:
>
> SELECT array_sort('{{2,3,4}}'::xid[]);
>
> This will return the array as is, but xid doesn't have a LT_OPR, should
> I error out in this case? like:
>
> could not identify ordering operator for type xid[]

Yes, I think that case needs to error out. It seems best to identify
the ordering operator before you decide whether or not you have >1
element.

-- 
Robert Haas
EDB: http://www.enterprisedb.com



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