Re: general purpose array_sort

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Junwang Zhao <zhjwpku@gmail.com>
Cc: Amit Langote <amitlangote09@gmail.com>, "David G. Johnston" <david.g.johnston@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, "andreas@proxel.se" <andreas@proxel.se>, Robert Haas <robertmhaas@gmail.com>
Date: 2024-10-11T05:12:40Z
Lists: pgsql-hackers
tricky case:
should we allow array element type to be composite/domain?
currently seems to work fine.


create table t(b int[]);
insert into t values ('{{1,3}}'), ('{{1,2}}');

 select array_sort((select array_agg(t) from t), 'desc');
            array_sort
-----------------------------------
 {"(\"{{1,3}}\")","(\"{{1,2}}\")"}


select array_sort((t.b)) from t;
ERROR:  multidimensional arrays sorting are not supported


select array_sort((select array_agg(t.b) from t));
ERROR:  multidimensional arrays sorting are not supported



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