I have a table looking like this:
CELL   day1      day2      day3      day4    ......   day365
1      3,7167    0         0         0,1487  ......   0,3256
2      0         0         0,2331    0,1461  ......   1,8765
3      1,431     0,4121    0         1,4321  ......   0
...
...
...
64800
I would like to transponse my table, so that I have my rows as columns and my columns as rows. A result looking like this:
DAY    1         2         3       ...... 64800  
day1   3,7167    0         1,431   ...... ......
day2   0         0         0,4121  ...... ......
day3   0         0,2331    0       ...... ......
day4   0,1487    0,1461    1,4321  ...... ......
...
...
...
day365
My biggest problem is the table size (365 columns and 64800 rows). How do I write a query where I dont have to define the columns I want in the output. Is there a way to create a table without defining each column and could you show my how my query would have to look like?
My second problem is that I dont even get the crosstab to work in a datasubset . The following query:
SELECT * FROM crosstab(
'SELECT * FROM 1997_subset  ORDER BY 1,2')
AS test("cell" int, "day1" double precision, "day2" double precision, "day3" double precision, "day4" double precision, "day5" double precision)
Gives me this mistake:
ERROR:  invalid source data SQL statement
DETAIL:  The provided SQL must return 3 columns: rowid, category, and values.
Help is very much appreciated, thank you very much!
 
    