I have a query like this:
select id, array_length(users_who_like_ids,1) as ct from queryables order by 2 desc;
But empty arrays (with no elements) sort on top. I'd rather have
array_length() return 0 for that case so that this would get sorted to the bottom.
I'm probably not understanding
array_length() (ok, definitely) but:
embers_dev2=# select array_length(array[1,2], 1), array_length(ARRAY::integer,1);
should return 0 rather than nothing (NULL), right?
Could I do an if statement like inline on it?
According to this related answer on SO, it looks like
COALESCE might be what I want - but I am open to better ideas: