In Postgres 8.3, I need to group by certain elements within an array field. When I group by the array itself, all possible combinations are shown. I only want to group by the element.
something like this works for finding the count of a single element:
SELECT count(*)
FROM table
WHERE foo=any(bar)
this will return the correct count for a single element in an array. How do I return multiple counts for all elements in an array? If I group by the array, it will use all array elements in the identical order they are stored (not what I need).
edit for clarity: bar is an array with values like {foo, some, thing} or {foo, thing} or {some, thing, else}
I want to know how many records have an element value of foo, some, thing, and else in the array "bar".