ARRAY_SORT

functionsupportedCore SQL functions

docs.snowflake.com ↗

Semi-structured and structured data functions

Returns 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

NameRequiredDescription
arrayrequiredThe ARRAY of elements to sort.
sort_ascendingoptionalSpecifies 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_firstoptionalSpecifies 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