I\'m using PostgreSQL 9.1 and I have this data structure:
A B ------- 1 a 1 a 1 b 1 c 1 c 1 c 1 d 2 e 2 e
Maybe I'm missing something, but this should do it:
SELECT a, count(*) as cnt, array_agg(b) as all_values FROM your_table GROUP BY a