Why no "array_sort" function? - Mailing list pgsql-hackers

From Fabien COELHO
Subject Why no "array_sort" function?
Date
Msg-id alpine.DEB.2.22.394.2005080947190.914063@pseudo
Whole thread Raw
Responses Re: Why no "array_sort" function?
List pgsql-hackers
Hello devs,

although having arrays is an anathema in a relational world, pg has them, 
and I find it useful for some queries, mostly in an aggregation to show 
in a compact way what items were grouped together.

There are a few functions available to deal with arrays. Among these 
functions, there is no "array_sort". It is easy enough to provide one that 
seems to work, such as:

   CREATE OR REPLACE FUNCTION array_sort(a ANYARRAY) RETURNS ANYARRAY
   IMMUTABLE  STRICT AS $$
     SELECT ARRAY_AGG(i) FROM (SELECT i FROM UNNEST(a) AS i ORDER BY 1) AS i;
   $$ LANGUAGE sql;

but I'm afraid that is is not particularly efficient, and I'm not even 
sure that it is deterministic (ok, the subquery is sorted, but the outside
query could still decide to scan it out of order for some reason?).

Is there a reason *not* to provide an "array_sort" function?

-- 
Fabien.



pgsql-hackers by date:

Previous
From: Justin Pryzby
Date:
Subject: should INSERT SELECT use a BulkInsertState?
Next
From: Peter Eisentraut
Date:
Subject: Re: ALTER TABLE ... SET STORAGE does not propagate to indexes