postgres crosstab with unknown number of categories
Seeing as you might be querying all months at some time, you could just add all the months to the crosstab query beforehand.


select * from crosstab 
    (
    'select project, month, hours from bar order by 1,2',
    $$SELECT unnest('{jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec}'::text[])$$
    ) as  c 
    (
    "project text" text, 
    "jan" int, "feb" int, "mar" int, "apr" int, 
    "may" int, "jun" int, "jul" int, "aug" int, 
    "sep" int, "oct" int, "nov" int, "dec" int
    );



  This solution is based on the answer to the question PostgreSQL Crosstab Query on stackoverflow.com.