Jan Dittmer <jdi@xxxxxxx> writes: > It would help if booleans could be casted to integer 1/0 :-) As of 8.1 there is such a cast in the system: regression=# select 't'::bool::int; int4 ------ 1 (1 row) In earlier releases you can make your own. As for the original question, though: have you looked at the crosstab functions in contrib/tablefunc? regards, tom lane