Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id C88FC1337B7B for ; Sat, 16 Oct 2010 00:23:34 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 36002-05 for ; Sat, 16 Oct 2010 03:23:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gmx.net (mailout-de.gmx.net [213.165.64.23]) by mail.postgresql.org (Postfix) with SMTP id F3F481337B7E for ; Sat, 16 Oct 2010 00:23:26 -0300 (ADT) Received: (qmail invoked by alias); 16 Oct 2010 03:23:24 -0000 Received: from mue-88-130-23-246.dsl.tropolys.de (EHLO [192.168.0.113]) [88.130.23.246] by mail.gmx.net (mp003) with SMTP; 16 Oct 2010 05:23:24 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX192r4pfe1N220rbl41MZPAlY+cPweVkGmN6SSJeQ6 BWDS9fZ/xOWSFc Message-ID: <4CB91AAE.6030602@gmx.net> Date: Sat, 16 Oct 2010 05:23:26 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: How to collect text-fields from multiple rows ? Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/39 X-Sequence-Number: 34690 Hi, how can I collect text-fields from multiple rows into one output row? I'd like to do an equivalent to the aggregate function SUM() only for text. The input is a select that shows among other things a numerical column where I would like to group by. The text column of all rows in a group should get concatenated into 1 text devided by a '\n'. Even better would be if I could add a second text colum per line as topic. Input e.g. select group_nr::integer, memo::text, topic::text ... 1, 'bla ', 'weather' 2, 'yada..', 'weather' 2, 'talk talk..', 'cooking' 2, 'words words, ...', 'poetry' 3, .... Output: 1, 'weather\nbla...' 2, 'weather\nyada..\ncooking\ntalk talk..\npoetry\nwords words, ...' Even better would be to get some kind of line-chars as optical devider between the topics. Lets say 10 = above all topic-lines. 2, '==========\nweather\nyada..\n==========\ncooking\ntalk talk..\n==========\npoetry\nwords words, ...'