From: | "Nacef LABIDI" <nacef(dot)l(at)gmail(dot)com> |
---|---|
To: | "Guillaume Lelarge" <guillaume(at)lelarge(dot)info> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Concat field result in select query |
Date: | 2008-08-22 14:15:01 |
Message-ID: | f16f7ea00808220715q1d7457a8p84764816207c4ac6@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Thank you, this is all what I need
On Fri, Aug 22, 2008 at 4:10 PM, Guillaume Lelarge
<guillaume(at)lelarge(dot)info>wrote:
> Nacef LABIDI a écrit :
> > Hi all,
> >
> > I was wondering if there is a way to concatenate the results of a field
> > in a select to return it as a single string.
> >
> > Example :
> >
> > my_field
> > --------------
> > 1
> > 2
> > 3
> >
> > select concat_something(my_field) from my_table group by something;
> > the result expected would be someting like that : 1/2/3 (with a
> > separator it would be really nice)
> >
> > I hope that I am not asking for too much ;)
> >
>
> Something like:
>
> SELECT array_to_string(array(select myfield from mytable), ','));
>
> For example:
>
> sherkin=# select * from t1;
> c1 | c2
> ----+----
> 1 |
> 2 | 3
> 2 | 4
> 2 | 5
> (4 lignes)
>
> sherkin=# SELECT array_to_string(array(select c1 from t1), ',');
> array_to_string
> -----------------
> 1,2,2,2
> (1 ligne)
>
>
> --
> Guillaume.
> http://www.postgresqlfr.org
> http://dalibo.com
>
From | Date | Subject | |
---|---|---|---|
Next Message | Julien Cigar | 2008-08-22 16:07:15 | Re: Concat field result in select query |
Previous Message | Guillaume Lelarge | 2008-08-22 14:10:05 | Re: Concat field result in select query |