How can we sort a MAP based on Keys in Aws Athena SQL
select map_from_entries(array_agg(row(a,b)))
from
(
SELECT a, b
FROM unnest(map(ARRAY[‘z’, ‘a’, ‘b’, ‘c’], ARRAY[1, 2, 3, 4])) AS t(a, b)
order by a desc
)
Would like to get {a=2, b=3, c=4, z=1} But I am getting {a=2, b=3, z=1, c=4}
Trino doesnt have function map_top_n_keys as in Presto.. Thanks
New contributor
Ramesh Azhakesan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.