Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 662 Bytes

udf-sort-array.md

File metadata and controls

35 lines (26 loc) · 662 Bytes

UDF: Sort Array

Description

Javascript UDF to sort an array in ascending order.

-- Create the UDF.
CREATE OR REPLACE FUNCTION array_sort(a array)
  RETURNS array
  LANGUAGE JAVASCRIPT
AS
$$
  return A.sort();
$$
;

-- Call the UDF with a small array.
SELECT ARRAY_SORT(PARSE_JSON('[2,4,5,3,1]'));

Example

SELECT ARRAY_SORT(PARSE_JSON('[2,4,5,3,1]')) as arr_sorted;
ARR_SORTED
[1,2,3,4,5]

References: