On Sat, Sep 28, 2024 at 7:52 PM Junwang Zhao <zhjw...@gmail.com> wrote: > > PFA v2, use COLLATE keyword to supply the collation suggested by > Andreas offlist. > this is better. otherwise we need extra care to handle case like: SELECT array_sort('{1,3,5,2,4,6}'::int[] COLLATE "pg_c_utf8");
+ <row> + <entry role="func_table_entry"><para role="func_signature"> + <indexterm> + <primary>array_sort</primary> + </indexterm> + <function>array_sort</function> ( <type>anyarray</type> <optional>, <parameter>dir</parameter> </optional>) + <returnvalue>anyarray</returnvalue> + </para> + <para> + Sorts the array in either ascending or descending order. + <parameter>dir</parameter> must be <literal>asc</literal> + or <literal>desc</literal>. The array must be empty or one-dimensional. + </para> + <para> + <literal>array_sort(ARRAY[1,2,5,6,3,4])</literal> + <returnvalue>{1,2,3,4,5,6}</returnvalue> + </para></entry> + </row> I am confused with <parameter>dir</parameter>. I guess you want to say "direction" But here, I think <parameter>sort_asc</parameter> would be more appropriate? <parameter>dir</parameter> can have only two potential values, make it as a boolean would be more easier? you didn't mention information: "by default, it will sort by ascending order; the sort collation by default is using the array element type's collation" tuplesort_begin_datum can do null-first, null-last, so the one-dimension array can allow null values. Based on the above and others, I did some refactoring, feel free to take it. my changes, changed the function signature, so you need to pay attention to sql test file.
array_sort_changes.no-cfbot
Description: Binary data