sort_array

Description

Return an array with the elements of the input array in sorted order.

sort_array accepts two options:

asc decides whether the elements are sorted in ascending order. Default is true (sort ascending).

nulls_first decides whether the NULLs are placed at the start or the end of the array. If nulls_first is not specified, NULLs are sorted last if asc is true or first if asc is false.

Return type

input_array

Domain

This is a scalar function (calculates a single output value for a single input row.)

Categories

Usage

sort_array(input_array, [ options ])

Argument

Type

Optional

Repeatable

Restrictions

input_array

array

no

no

none

options

options

yes

no

constant

Options

Option

Type

Meaning

asc

bool

Sorts the elements in ascending order if asc is true or in descending order if asc is false. Default is true (ascending).

nulls_first

bool

NULLs are placed at the start of the array if nulls_first is true or at the end of the array if nulls_first is false. If nulls_first is not specified, NULLs are sorted last if asc is TRUE or first if asc is FALSE.

Examples

make_col sorted_arr:sort_array(input_array)

Make a new column sorted_arr, which contains the sorted elements in ascending order.

make_col sorted_arr:sort_array(input_array, options(asc:false))

Make a new column sorted_arr, which contains the sorted elements in descending order.

make_col sorted_arr:sort_array(input_array, options(asc:true, nulls_first:true))

Make a new column sorted_arr, which contains the sorted elements in ascending order and NULLs placed at the start of the sorted array.