Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 6789A2E02FF for ; Wed, 5 Dec 2007 07:16:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 91440-10 for ; Wed, 5 Dec 2007 07:15:55 -0400 (AST) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by postgresql.org (Postfix) with ESMTP id 414B62E0377 for ; Wed, 5 Dec 2007 07:15:59 -0400 (AST) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mrelayeu6) with ESMTP (Nemesis) id 0ML29c-1IzsEP0D8h-0001VG; Wed, 05 Dec 2007 12:15:57 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1IzsEL-0000YO-00; Wed, 05 Dec 2007 12:15:53 +0100 Date: Wed, 5 Dec 2007 12:15:53 +0100 From: "A. Kretschmer" To: Ashish Karalkar , pgsql-general@postgresql.org Subject: Re: SQL Query Message-ID: <20071205111553.GF24799@a-kretschmer.de> References: <20071205103548.GD24799@a-kretschmer.de> <33481.2408.qm@web94314.mail.in2.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33481.2408.qm@web94314.mail.in2.yahoo.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1/XSEanJwarnIcVqpI8BDFu8nBsLy6eAjp9iyX ozMXAIO5wTQGdzBPibMFfwQrh6RllXulYOqjkSImAmSpO1TkW6 rz6Ee6rswo3uzqhD90Yy2UPjSr2Xst1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/244 X-Sequence-Number: 124988 am Wed, dem 05.12.2007, um 10:47:44 +0000 mailte Ashish Karalkar folgendes: > > X Y > > ------------ > > 1 ABC > > 2 PQR > > 3 XYZ > > 4 LMN > > 1 LMN > > 2 XYZ > > > > I want a query that will give me following output > > > > 1 ABC:LMN > > 2 PQR:XYZ > > 3 XYZ > > 4 LMN > > > > Any help will be really helpful > > You need a new aggregate-function. A solution for a similar problem (but > with comma instead :) can you find here: > http://www.zigo.dhs.org/postgresql/#comma_aggregate > > Thanks Andreas for your replay. > But i don't have an option two send argument to the store proc nither do i > know how many multiple records are there for a single X. I want result for > all rows of table. > > I dont thnink that function will give desired output. test=# create table Ashish ( x int, y text); CREATE TABLE test=*# copy ashish from stdin; Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself. >> 1 abc >> 2 pqr >> 3 yxz >> 4 lmn >> 1 lmn >> 2 xyz >> \. test=*# CREATE FUNCTION my_aggregate(text,text) RETURNS text AS ' SELECT CASE WHEN $1 <> '''' THEN $1 || '':'' || $2 ELSE $2 END; ' LANGUAGE sql IMMUTABLE STRICT; CREATE AGGREGATE my_comma (basetype=text, sfunc=my_aggregate , stype=text, initcond='' ); CREATE FUNCTION CREATE AGGREGATE test=*# select x, my_comma(y) from ashish group by x; x | my_comma ---+---------- 4 | lmn 3 | yxz 2 | pqr:xyz 1 | abc:lmn (4 rows) Okay, i forgot to sort and the chars are in lower case... Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net