Checking if a map or array is empty in Presto?

Leo Jiang picture Leo Jiang · May 26, 2017 · Viewed 19.6k times · Source

How do I check if a map has no keys in Presto? If I have a way to check if an array is empty, I can use the map_keys function to determine if the map is empty.

Answer

FreePeter picture FreePeter · Jun 1, 2017

You can use the cardinality function: https://prestodb.io/docs/current/functions/array.html#cardinality

select cardinality(array[]) = 0;
 _col0
-------
 true
(1 row)