Hello
> mostly in an aggregation to show
> in a compact way what items were grouped together.
Aggregate functions have syntax for ordering: just "select array_agg(i order by i) from ...."
Described here: https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-AGGREGATES
regards, Sergei