Thanks to visit codestin.com
Credit goes to postgrespro.com

Re: Generating a cross tab (pivot table) - Mailing list pgsql-sql

From Joe Conway
Subject Re: Generating a cross tab (pivot table)
Date
Msg-id [email protected]
Whole thread Raw
In response to Generating a cross tab (pivot table)  (Christoph Haller <[email protected]>)
List pgsql-sql
Richard Huxton wrote:
> On Thursday 07 Nov 2002 11:47 am, Christoph Haller wrote:
> 
>>Regarding to Terry's request on multiple aggregates and
>>Shahbaz's request for generating a cross tab ( pivot table )
>>in September, I've found an excellent example on a german inet page
>>http://www.itrain.de/
>>I've translated it and think it's useful for many who subscribed
>>(I hope so, maybe it was told before, but I couldn't find
>>anything about this topic in the techdecs).
> 
> Very useful. Also note there are some examples of how to produce crosstab 
> results in the table-functions contrib directory in 7.3
> 

Just to amplify a bit, in contrib/tablefunc there is a family of functions 
called crosstabN(), where N is 2, 3 and 4. These are meant as examples -- you 
could, for example, create a function crosstab5() if you need it. There is 
also a function called crosstab(), which returns type RECORD and thus requires 
the column definition to be specified in the query. See 
contrib/tablefunc/README.tablefunc for more details and examples.

These were done as relatively crude examples and therefore have some 
limitations which may or may not be a problem for you. If people find the 
functions useful and provide suggestions for improvement in functionality I'll 
try to upgrade them for 7.4.

Thanks,

Joe



pgsql-sql by date:

Previous
From: "Rison, Stuart"
Date:
Subject: Re: Copying a rowtype variable.
Next
From: Tom Lane
Date:
Subject: Re: PLpgSQL FOR IN EXECUTE question