I'm using Postgres 8.4.9 and having trouble getting their crosstab to work.
Here are what my data look like:
rowname | bucket | bucket_value
----------------+---------------------+--------------
CL100001 10011 | 1 A01 | 01/01/2001 | 14 16
CL100001 10011 | 1 A01 | 01/01/2001 |
CL100001 10011 | 1 A01 | 01/01/2001 |
CL100001 10011 | 1 A01 | 01/01/2001 | 440 480
CL100001 10011 | 1 A01 | 01/01/2001 | 475 475
CL100002 10021 | 1 B01 | 01/01/2001 | 16 16
CL100002 10021 | 1 B01 | 01/01/2001 |
CL100002 10021 | 1 B01 | 01/01/2001 |
CL100002 10021 | 1 B01 | 01/01/2001 | 440 480
CL100002 10021 | 1 B01 | 01/01/2001 | 475 475
CL100003 10030 | 1 C01 | 01/01/2001 | 14 16
CL100003 10030 | 1 C01 | 01/01/2001 |
CL100003 10030 | 1 C01 | 01/01/2001 |
CL100003 10030 | 1 C01 | 01/01/2001 | 440 440
CL100003 10030 | 1 C01 | 01/01/2001 | 475 475
...
This is selected from a table, ct, that is used to prepare the data.
Next, my query looks like
SELECT gtreport.* FROM crosstab('SELECT
rowname,
bucket,
bucket_value
FROM
ct
ORDER BY
rowname, bucket',
'SELECT DISTINCT
markername
FROM
markers M,
genotypes G,
gsamples S,
guploads U
WHERE
M.markerid=G.markers_id
AND G.gsamples_id=S.id
AND S.guploads_id=U.id
AND ( U.ibg_study_id=15 AND U.ibg_project_id is NULL)
ORDER BY
M.markername')
AS gtreport(
labid text,
box_well_run_date text,
HTTLPR text,
Amelo text,
Caspi text,
DAT1 text,
DRD4 text)
Which I've tried to construct following the Postgres documentation as well as I can. But this produces the error "Query-specified return tuple has 7 columns but crosstab returns 6."
Which is baffling. If anyone sees what I've done wrong, it would be much appreciated....
--Rick