Sure, you can use the ARRAY function. It supports an optional ORDER BY clause. You haven't provided sample data, but supposing that you have a top level array column named arr
, you can do something like this:
SELECT col1, col2, ARRAY(SELECT x FROM UNNEST(arr) AS x ORDER BY x) AS arrFROM MyTable;
This sorts the elements of arr
by their values.
If you actually have an array of a struct type, such as ARRAY<STRUCT<a INT64, b STRING>>
, you can sort by one of the struct fields:
SELECT col1, col2, ARRAY(SELECT x FROM UNNEST(arr) AS x ORDER BY a) AS arrFROM MyTable;