From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: The Hermit Hacker <scrappy@hub.org>
To: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Odd "problem", not sure if there is a solution ....
Date: Sun, 28 Mar 1999 17:48:20 +0200
Message-ID: <l03110709b323fe6728a1@[147.233.148.142]> (raw)
In-Reply-To: <Pine.BSF.4.05.9903252343280.389-100000@thelab.hub.org>
At 05:46 +0200 on 26/03/1999, The Hermit Hacker wrote:
> am working up a database for client that contains answers for online
> testing...right now, the 'tables' look like:
>
> userid Q1 Q2 Q3 Q4 Q5 Q6 Q7 etc
>
> I want to change it so that its more generic, as:
>
> userid question_no answer
>
> so that instead of one row per user, there are X rows...
>
> the problem is that, somehow, I want the client to be able to view the
> results as the first format (ie. one line per user) with it being stored
> as multiple lines per user...
>
> Possible?
The question is whether you expect your query to return rows in the above
format, where each of the answers is a separate field, or you could settle
for all the answers returned in one text field.
SQL does not provide for queries that return a different number of fields
for each row. What I'd do in such a case is to create an aggregate function
based on text concatenation ('||'), and either use the result as is or
split it on the client side through known delimiters.
Another approach is to query this table separately and do the grouping on
the client side.
I've used the first approach in one of my projects, if you are interested
in the solution.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: herouth@oumail.openu.ac.il, scrappy@hub.org
Subject: Re: [SQL] Odd "problem", not sure if there is a solution ....
In-Reply-To: <l03110709b323fe6728a1@[147.233.148.142]>
References: <Pine.BSF.4.05.9903252343280.389-100000@thelab.hub.org> <l03110709b323fe6728a1@[147.233.148.142]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox