Postgresql WITH clause in crosstab queries
You want to have your CTE fully contained within the crosstab.More like this... you can have a CTE in a crosstab, but not vice-versa.
SELECT * FROM CROSSTAB($$ WITH month_index AS ( SELECT rowid AS row_name, CONCAT(''m'',monthno) AS category, nic5dindex AS value FROM source_data_table ) SELECT * FROM month_index , '*<categorysql>*'$$ )AS ct(..)