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
This is what you need:
SELECT A, COUNT(*), array_agg(b) FROM YourTable GROUP BY A