arraySort
Description
Returns a new array with the elements sorted according to the specified options.
- The element type must match the array type.
- Supported element types include
string
,bool
,number
,interval
,timestamp
,regexp
, andenum
. - By default, the array is sorted in ascending order, with null values appearing last.
Syntax
Like many functions in DataPrime, arraySort
supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
Name | Type | Required | Description |
---|---|---|---|
array | array | true | The array to sort |
desc | bool | false | Sort order flag. When true , the array is sorted in descending order. Must be a literal. Defaults to false . |
nullsFirst | bool | false | Null placement flag. When true , null values appear at the start of the output. Must be a literal. Defaults to false . |
Example
Use case: Sort names alphabetically
Suppose you have a list of names. Consider the following input:
By applying arraySort
, you can sort the list alphabetically in ascending order.
Output
The result will include the array sorted alphabetically:
Theme
Light