Crosstab Question - Mailing list pgsql-general

From David Blewett
Subject Crosstab Question
Date
Msg-id 46BA5E8C.9020708@dawninglight.net
Whole thread Raw
Responses Re: Crosstab Question  (Michael Glaesemann <grzm@seespotcode.net>)
List pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi All:

I'm building an application along the lines of the questionnaire
design on varlena.com [1], with slight modifications. In my design,
there's a table called chartversionquestion that collects different
questions into a bundle to create the questionnaire.

Using a view [2] very similar to the one on varlena, I pull all the
data from the value tables into one long list (cast to text). I
would like to be able to create a crosstab from this view such that
the short question name becomes a column header, with the related
value underneath.

Since the number of questions to be pivoted will vary per
questionnaire the method should accept a number of columns
parameter. The crosstab in the tablefunc contrib module expects the
columns to be explicitly identified before hand. I suppose it could
be possible to write a simple function to wrap the crosstab_n_cols
functions to be able to return a variable number, but that seems
hackish. Are there any other alternatives?

David Blewett

[1] http://www.varlena.com/GeneralBits/110.php
[2] http://www.varlena.com/varlena/GeneralBits/Tidbits/QnA/views.sql
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGul6MZmlc6wNjtLYRCA5hAJ9fSHjNI5gQs/eqZ85bHl4ZrGWG3ACfbEnG
zo1KFvZL8LraBESRySyVryg=
=w1Z8
-----END PGP SIGNATURE-----

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Reordering columns, will this ever be simple?
Next
From: Scott Ribe
Date:
Subject: Re: Take your postgresSql on the road, and live to tell of it.