ARRAY_SORT

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Sorts the elements of an array in ascending or descending order.

  • input_array: The array to sort.
  • ascending: A boolean flag that indicates the sort order. When true (default), sorts in ascending order. When false, sorts in descending order.

Returns an array with elements sorted in the specified order. NULL values are always first in the output array.

  • NULL values are always first in the output array, regardless of sort order.
  • The default sort order is ascending.

Sort an array in ascending order (default behavior).

Returns array[1, 1, 2, 3, 4, 5, 6, 9], sorted in ascending order.

Sort an array in descending order using the optional flag.

Returns array[9, 6, 5, 4, 3, 2, 1, 1], sorted in descending order.

Sort an array that contains NULL values.

Returns array[null, null, 1, 2, 3]. NULL values are first, followed by the sorted non-NULL values.