PostgreSQL码农集散地

PostgreSQL 18 preview - 新增函数array_sort 支持数组元素排序

PostgreSQL 18 preview - 新增函数array_sort 支持数组元素排序

PostgreSQL 18 新增了支持array 内元素排序的SQL 函数array_sort, 之前版本需要通过intarray插件来支持.

SELECT array_sort('{1.1,3.3,5.5,2.2,4.4,6.6}'::numeric[]);  
         array_sort           
 ---------------------------  
  {1.1,2.2,3.3,4.4,5.5,6.6}  
 (1 row)  

https://www.postgresql.org/docs/current/intarray.html

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=6c12ae09f5a5d6c153eaea7901542591dc28fb9e

Introduce a SQL-callable function array_sort(anyarray).  
author Tom Lane <[email protected]>   
Tue, 1 Apr 2025 22:03:55 +0000 (18:03 -0400)  
committer Tom Lane <[email protected]>   
Tue, 1 Apr 2025 22:03:55 +0000 (18:03 -0400)  
commit 6c12ae09f5a5d6c153eaea7901542591dc28fb9e  
tree 49e351e00c0f30aa00bac57a2dbbaedd9329ebfa tree  
parent 6da2ba1d8a031984eb016fed6741bb2ac945f19d commit | 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