From: | Bianca Stephani <bianca(dot)stephani(at)gmail(dot)com> |
---|---|
To: | Christoffer Westring <dille(dot)westring(at)gmail(dot)com> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Doubt about query |
Date: | 2015-06-08 11:41:45 |
Message-ID: | CAL5He_cTpNj=uSebhBRMarKx_GPMNdj8b_+xDM5MFKMHDU23Dw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On Mon, Jun 8, 2015 at 4:38 AM, Christoffer Westring <
dille(dot)westring(at)gmail(dot)com> wrote:
> 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.
>
>
Thanks, but i don't want the top 5 records. I maybe have not been clear
about what I want...
I have a table with N columns. Of this N, i want the value of 5 columns.
So, if I do a normal select, i would get something like:
column1 column2 column3 column4 column5
value1row1 value2row1 value3row1 value4row1 value5row1
value1row2 value2row2 value3row2 value4row2 value5row2
value1row3 value2row3 value3row3 value4row3 value5row3
And what i really want is:
column
[value1row1,value2row1, value3row1, value4row1, value5row1, value1row2 ,
value2row2, value3row2, value4row2, value5row2, value1row3, value2row3,
value3row3, value4row3, value5row3]
Can I do that?
> 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.
>
>
--
Bianca Stephani.
*"Killing time before time kill us""Panic called you out and took you in,
giving you an easy game and letting you win""Who's gonna love you when you
reach the end?""A diferença entre a vida e a arte é que a arte é mais
suportável""Smile like you mean it""I told you I was brave, but I've
lied""If you don't do anything, nothing can happen"*
From | Date | Subject | |
---|---|---|---|
Next Message | Federico Leoni | 2015-06-08 12:59:26 | [Newbie] Postgresql for Odoo/Python: Concatenate rows value until condition = true? |
Previous Message | Christoffer Westring | 2015-06-08 07:38:54 | Re: Doubt about query |