ARRAY_SORT
functionsupportedCore SQL functionsReturns an ARRAY that contains the elements of the input ARRAY sorted in ascending or descending order. You can specify whether or not NULL elements are sorted before or after non-NULL elements.
Syntax
supportedpartialnot supportednot scored
ARRAY_SORT( <array> [ , <sort_ascending> [ , <nulls_first> ] ] )
Parameters
| Name | Required | Description |
|---|---|---|
array | required | The ARRAY of elements to sort. |
sort_ascending | optional | Specifies whether to sort the elements in ascending or descending order: Specify TRUE to sort the elements in ascending order. Specify FALSE to sort the elements in descending order. Default: TRUE |
nulls_first | optional | Specifies whether to place SQL NULL elements at the beginning or end of the sorted ARRAY: Specify TRUE to place the SQL NULL elements first in the ARRAY. Specify FALSE to place the SQL NULL elements last in the ARRAY. Default: FALSE if the ARRAY is sorted in ascending order; TRUE if the ARRAY is sorted in descending order. This argument only affects the order of SQL NULL elements. This does not affect the order of JSON null elements. |
Returns
This function returns an ARRAY that contains the elements of array in sorted order.
Usage notes
- The sort order is equivalent to the order resulting from flattening the ARRAY and specifying an ORDER BY clause with the corresponding ASC | DESC and NULLS FIRST | LAST parameters.
- If any of the input arguments is NULL, the function returns NULL.
- This function is not guaranteed to provide a stable sort when the ARRAY contains either of the following: Elements of two different numeric or timestamp types.
- Objects containing two different numeric or timestamp types.