X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id EB58BD1CCD0 for ; Mon, 1 Dec 2003 20:02:07 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 71614-02 for ; Mon, 1 Dec 2003 16:01:38 -0400 (AST) Received: from serwer.skawsoft.com.pl (skawina.eu.org [80.48.213.66]) by svr1.postgresql.org (Postfix) with ESMTP id 5D4EAD1DA92 for ; Mon, 1 Dec 2003 16:01:20 -0400 (AST) Received: from klaster.net (core-1.citynet.pl [80.48.135.69]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 0AABA2B40F; Mon, 1 Dec 2003 21:00:41 +0100 (CET) Message-ID: <3FCB9E01.6010405@klaster.net> Date: Mon, 01 Dec 2003 21:01:05 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.5) Gecko/20031007 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Kumar Cc: psql Subject: Re: Concatenating multiple fetches into a single string References: <024a01c3b802$d9afac40$7502a8c0@hdsc.com> In-Reply-To: <024a01c3b802$d9afac40$7502a8c0@hdsc.com> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/3 X-Sequence-Number: 16169 Dnia 2003-12-01 13:01, Użytkownik Kumar napisał: > Dear Friends, > > I am doing a migration from SQL server to Postgres SQL. A simple select > fetches the following names. > > select full_name FROM project_members where > project_members.project_role_id in (' + @p_res_ids + ') ; > > Let us say if the results are > > full_name > --------------- > David > Postgres > plpgsql > > I need to send the out put as David,Postgres,Plsql -- one string, > concatenates the fetches from multiple rows. This was handled in SQL > server with a cursor. I can't find simpler function (if I remember well, there is such one), so there is my version of aggregate function you need: create or replace function comma_aggregate(varchar,varchar) returns varchar as ' begin if length($1)>0 and length($2)>0 then return $1 || '', '' || $2; elsif length($2)>0 then return $2; end if; return $1; end; ' language 'plpgsql'; drop aggregate comma(varchar) cascade; create aggregate comma (basetype=varchar, sfunc=comma_aggregate, stype=varchar, initcond='' ); Regards, Tomasz Myrta