Re: Generating a cross tab (pivot table)

From: Joe Conway <mail(at)joeconway(dot)com>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: Christoph Haller <ch(at)rodos(dot)fzk(dot)de>, pgsql-sql(at)postgresql(dot)org, terry(at)ashtonwoodshomes(dot)com, chaudhar(at)umich(dot)edu
Subject: Re: Generating a cross tab (pivot table)
Date: 2002-11-07 17:25:37
Message-ID: 3DCAA211.3020402@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-11-07 18:01:31 Re: PLpgSQL FOR IN EXECUTE question
Previous Message Rison, Stuart 2002-11-07 16:51:37 Re: Copying a rowtype variable.