Checking if a map or array is empty in Presto? Checking if a map or array is empty in Presto? sql sql

Checking if a map or array is empty in Presto?


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

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


To check array is empty just compare it with = array[].Example:

presto> select (map_keys(map(array[], array[])) = array[]) as is_empty; is_empty---------- true(1 row)

Likewise, to check if a map is empty just compare it with = map().Example:

presto> select (map(array[], array[]) = map()) as is_empty; is_empty---------- true(1 row)