I have a postgres table with the following format:
id key value ------------------------------------- a 1 p b 2 q c 3 r a 2 s
I want to convert it into the following format:
id 1 2 3 -------------------------------------------- a p s b q c r
I am trying to using the following crosstab() query to do this:
create extension tablefunc;
select * from crosstab(
'select id, key, value
from table
order by 1,2')
as ct(id text, key integer, value text);
However, it fails with the following exception:
ERROR: return and sql tuple descriptions are incompatible
********** Error **********
ERROR: return and sql tuple descriptions are incompatible
SQL state: 42601
What am I missing here?
Update: There are around 25 keys in the table.