Scalar function
NULL array or NULL flag returns NULL.
Syntax
Scalar
Arguments
Type notation used below:
- T is the array element type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY or STRUCT.
Returns
- Type: ARRAY<T>
- Possible values: Sorted elements.
- NULL behavior: NULL array or NULL flag returns NULL.
- Shape: Same element count/type.
- Ordering: Ascending NULLs first, or descending NULLs last.
Properties
Usage notes
- Floating-point sorting distinguishes positive and negative zero and different NaN values. STRING and BINARY values use lexicographic order. Nested arrays and structs are sorted by their elements or fields.
- INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
Examples
Typical behavior
Sort strings with a NULL element
Limitations
- ascending must be BOOLEAN literal; elements must support sorting.
- Elements must have comparable types. The relative order of equal values is not guaranteed.
- MAP elements, including MAP values nested inside compared elements, are outside the supported element types.
Last modified on October 15, 2026