Re: Turning column into row

From: "Tille, Andreas" <TilleA(at)rki(dot)de>
To: rmello(at)fslc(dot)usu(dot)edu
Cc: PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Turning column into row
Date: 2002-05-23 09:24:25
Message-ID: Pine.LNX.4.44.0205231119570.8932-100000@wr-linux02.rki.ivbb.bund.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 22 May 2002, Joel Burton wrote:

> http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=13
> 9 will do as a LIST() replacement.
While beeing a great hint it has a syntactical mistake.

The correct syntax would be:

-- creat function to comma-ify a list

create function comma_aggregate(text,text) returns text as '
begin
if (length($1) > 0 ) then
return $1 || '', '' || $2; /* note the '' here !! */
else
return $2;
end if;
end;
' language 'plpgsql';

A further question: Is there any possibility to add a further flag in the
way:

select fname, lname, comma(hobbies,SPORT_FLAG) from people join hobbies on (personid) group by personid, fname, lname, SPORT_FLAG;

So that we get only those hobbies listed which have SPORT_FLAG = 1
or something else?

Kind regards

Andreas.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gabriel Dovalo Carril 2002-05-23 10:34:45 Functions with dynamic queries
Previous Message Denis 2002-05-23 08:18:17 Re: Further info : Very high load average but no cpu utilization ?