Re: Concat field result in select query - Mailing list pgsql-sql

From Guillaume Lelarge
Subject Re: Concat field result in select query
Date
Msg-id 48AEC8BD.2020308@lelarge.info
Whole thread Raw
In response to Concat field result in select query  ("Nacef LABIDI" <nacef.l@gmail.com>)
Responses Re: Concat field result in select query
List pgsql-sql
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.orghttp://dalibo.com


pgsql-sql by date:

Previous
From: Julien Cigar
Date:
Subject: Re: Concat field result in select query
Next
From: "Nacef LABIDI"
Date:
Subject: Re: Concat field result in select query