From: | Christoffer Westring <dille(dot)westring(at)gmail(dot)com> |
---|---|
To: | bianca(dot)stephani(at)gmail(dot)com |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Doubt about query |
Date: | 2015-06-08 07:38:54 |
Message-ID: | CAAvBpS=TvASx22--fMsiwFYiwbH7wo8F=TwN28qwY3Hc+iFEqQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hi Bianca,
What are you looking for, I think it is the "string_agg" function.
So for example the following query:
"Select string_agg(name, ', ') from table;"
will return "name1, name2, ....".
If you need top 5 rows you can add "limit 5" or other conditions you need.
Hope it helps.
On 05.06.2015, at 20:25, Bianca Stephani <bianca(dot)stephani(at)gmail(dot)com> wrote:
HI everyone.
I have a table with X columns. And I want to make a select of 5 of the X
columns in a way that i get all the 5 columns values only in one column
(like i call everyone "AS bla" and as result, bla is an array of that
columns), but if i use 5 selects with UNION ALL i just get [{bla => 3},
{bla => 3}, {bla => 1}, {bla => 5}, {bla => 2} ...] even with a GROUP BY.
And besides that, using "as bla" is turning my results (3, 1, 5, 2) into
strings.
What is the best way to collect the value of multiple integer columns as
one? :|
Thanks.
From | Date | Subject | |
---|---|---|---|
Next Message | Bianca Stephani | 2015-06-08 11:41:45 | Re: Doubt about query |
Previous Message | Gavin Flower | 2015-06-07 23:13:14 | Re: Doubt about query |