Re: Concatenating multiple fetches into a single string - Mailing list pgsql-sql

From Tomasz Myrta
Subject Re: Concatenating multiple fetches into a single string
Date
Msg-id 3FCC2C2E.2050106@klaster.net
Whole thread Raw
In response to Re: Concatenating multiple fetches into a single string  ("Kumar" <sgnerd@yahoo.com.sg>)
List pgsql-sql
Dnia 2003-12-02 05:51, Użytkownik Kumar napisał:
> Thanks for your reply.
> 
> But how to use this comma_aggregate( ) function to concatenate the fetched
> columns values from a select statement. In my example my select stmt fetches
> the following 3 rows. How can I use this function to concatenate them.
> 
> Select full_name FROM project_members where project_members.project_role_id
> in ( ' x,y,z ') ;
> 
>  full_name
>  ---------------
>  David
>  Postgres
>  plpgsql
> 
> Expected return string is - 'David,Postgres,Plsql'

Where is the problem?
It's an aggregate function - you use it like the other ones:

select comma(full_name) from...

There is one problem with this function - strings order is unexpectable, 
but you can always sort them in subselect before using this function:

select comma(full_name) from
(select full_name from .... order by full_name) X;

Regards,
Tomasz Myrta




pgsql-sql by date:

Previous
From: Bob Smith
Date:
Subject: Problem with intervals
Next
From: Richard Huxton
Date:
Subject: Re: Problem with intervals