Re: contrib/tablefunc crosstab - Mailing list pgsql-sql

From Joe Conway
Subject Re: contrib/tablefunc crosstab
Date
Msg-id 41127A0B.5030807@joeconway.com
Whole thread Raw
In response to contrib/tablefunc crosstab  (Caleb Simonyi-Gindele <csg@bordervet.ca>)
List pgsql-sql
Caleb Simonyi-Gindele wrote:
> My problem is that the rows are populated from right to left irrespective of
> the column. So the $561.99 in vet1 actually belongs to vet2. There are never
> any blank cells in the middle or start of a row - they always come at the
> end. How do I get the amount for that date into the appropriate column?

You either need to be sure there are no "gaps" in your source rows 
(provide one row for every category for each group, e.g. by doing an 
outer join) or use the hashed version of the function. Search the README 
for:

crosstab(text source_sql, text category_sql)

That is the hashed version that will do what you're looking for.

HTH,

Joe


pgsql-sql by date:

Previous
From: Caleb Simonyi-Gindele
Date:
Subject: contrib/tablefunc crosstab
Next
From: Michalis Kabrianis
Date:
Subject: Sum and count weird results