Skip site navigation (1) Skip section navigation (2)

Re: custom crosstab question

From: Joe Conway <mail(at)joeconway(dot)com>
To: Michael Swierczek <mike(dot)swierczek(at)gmail(dot)com>
Cc: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: custom crosstab question
Date: 2007-04-26 10:16:35
Message-ID: (view raw or whole thread)
Lists: pgsql-novice
Michael Swierczek wrote:
> On 4/25/07, Michael Swierczek <mike(dot)swierczek(at)gmail(dot)com> wrote:
>> Joe,
>>      That's exactly what I needed.   I completely missed that it would
>> be possible with the tablefunc/crosstab.   Since you're the main
>> (only?) name I see associated with that code, I'm sure you would know.
>> -Mike
> I spoke too soon, there's an additional factor at play that
> complicates things.
> Most of the questions take a single answer, but the multiple select
> questions can have several answers.   So for a regular question with
> code 'drug', a given survey_event can have 0 or 1 entries in the
> answer table with question_code 'drug'.  For a multiple select
> question like, 'health', 0-7 entries are possible in the answer table,
> and we want them exported as columns 'health0', 'health1', 'health2'
> through 'health7' and each column populated according to whether that
> section of the multiple select was chosen.

It seems to me that if you really want health0 and health1 tracked 
independently, they should each be considered separate questions. Then 
the existing code would "just work". Perhaps if it is important to tie 
those "healthN" questions together, you could have some other attribute 
for questions that allows grouping. So, for example, grp_id = 0 means 
this question is "stand alone" and grp_id > 0 is a grouped question. 
Something like:

create table survey_question_grps (
  grp_id int,
  grp_name text

insert into survey_question_grps values
(0, 'stand alone question'),
(1, 'health');

create table survey_question (
  id int,
  survey_id int,
  question_code text,
  grp_id int,
  question_order int

insert into survey_question values


In response to


pgsql-novice by date

Next:From: LukasDate: 2007-04-26 10:21:47
Subject: pg_dump slave DB
Previous:From: Reinhard HnatDate: 2007-04-26 10:08:08
Subject: How long does commit take?

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group