Re: Join field values

From: Ragnar <gnari(at)hive(dot)is>
To: veejar <veejar(dot)net(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Join field values
Date: 2007-06-05 17:39:07
Message-ID: 1181065148.5953.25.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On þri, 2007-06-05 at 19:33 +0300, veejar wrote:
> Hello!
>
> I have such field in my table:
>
> field1
> -------
> 1
> 2
> 3
> 4
> 5
>
>
> I want to get such result from select:
> '1,2,3,4,5' - join all values in field1 with ','
> // result must be varchar.
>
> Help to write SELECT-query for this task.

create an aggregate function and use that in your select.
http://www.postgresql.org/docs/8.2/static/sql-createaggregate.html

google reminded me of the mysql compatibility project,
whose implementation for group_concat() can be found here:
http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/mysqlcompat/mysqlcompat/aggregate.sql?rev=1.2&content-type=text/x-cvsweb-markup

gnari

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Childs 2007-06-05 18:29:02 Creditcard Number Security was Re: Encrypted column
Previous Message volunteer 2007-06-05 17:16:41 Re: lo or bytea streaming engine??