diff options
author | Tom Lane | 2025-04-01 22:03:55 +0000 |
---|---|---|
committer | Tom Lane | 2025-04-01 22:03:55 +0000 |
commit | 6c12ae09f5a5d6c153eaea7901542591dc28fb9e (patch) | |
tree | 49e351e00c0f30aa00bac57a2dbbaedd9329ebfa /doc | |
parent | 6da2ba1d8a031984eb016fed6741bb2ac945f19d (diff) |
Introduce a SQL-callable function array_sort(anyarray).
Create a function that will sort the elements of an array
according to the element type's sort order. If the array
has more than one dimension, the sub-arrays of the first
dimension are sorted per normal array-comparison rules,
leaving their contents alone.
In support of this, add pg_type.typarray to the set of fields
cached by the typcache.
Author: Junwang Zhao <[email protected]>
Co-authored-by: Jian He <[email protected]>
Reviewed-by: Aleksander Alekseev <[email protected]>
Discussion: https://postgr.es/m/CAEG8a3J41a4dpw_-F94fF-JPRXYxw-GfsgoGotKcjs9LVfEEvw@mail.gmail.com
Diffstat (limited to 'doc')
-rw-r--r-- | doc/src/sgml/func.sgml | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 5bf6656deca..2488e9ba998 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -20743,6 +20743,42 @@ SELECT NULLIF(value, '(none)') ... <row> <entry role="func_table_entry"><para role="func_signature"> + <indexterm> + <primary>array_sort</primary> + </indexterm> + <function>array_sort</function> ( + <parameter>array</parameter> <type>anyarray</type> + <optional>, <parameter>descending</parameter> <type>boolean</type> + <optional>, <parameter>nulls_first</parameter> <type>boolean</type> + </optional></optional> ) + <returnvalue>anyarray</returnvalue> + </para> + <para> + Sorts the first dimension of the array. + The sort order is determined by the default sort ordering of the + array's element type; however, if the element type is collatable, + the collation to use can be specified by adding + a <literal>COLLATE</literal> clause to + the <parameter>array</parameter> argument. + </para> + <para> + If <parameter>descending</parameter> is true then sort in + descending order, otherwise ascending order. If omitted, the + default is ascending order. + If <parameter>nulls_first</parameter> is true then nulls appear + before non-null values, otherwise nulls appear after non-null + values. + If omitted, <parameter>nulls_first</parameter> is taken to have + the same value as <parameter>descending</parameter>. + </para> + <para> + <literal>array_sort(ARRAY[[2,4],[2,1],[6,5]])</literal> + <returnvalue>{{2,1},{2,4},{6,5}}</returnvalue> + </para></entry> + </row> + + <row> + <entry role="func_table_entry"><para role="func_signature"> <indexterm id="function-array-to-string"> <primary>array_to_string</primary> </indexterm> |