Re: Doubt about query

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Bianca Stephani <bianca(dot)stephani(at)gmail(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Doubt about query
Date: 2015-06-07 23:07:09
Message-ID: CAKFQuwb2S45rYDokZ0DdFcbqkd9hZPUGYJ=1mMfUXt=tvfHGMg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Sun, Jun 7, 2015 at 6:51 PM, Bianca Stephani <bianca(dot)stephani(at)gmail(dot)com>
wrote:

> I'm sorry. What is "top-post"? :/
>

​When you response is above the previous message as opposed to following it
like mine do.​

>
> What I want exactly is to get all the values from rows from all 5 coluns
> into only one row and one column.
>
> A normal select of columns A, B, C, D would get 5 rows each one with 5
> columns with 1 integer each rowXcolumn, for example. I want as result (*as
> integer, not string*) a single column and single row with a list of
> integers. Is that possible?
>
> What you suggested to me as sql, give me a string of integers
> "1,2,3,4,5,6" and not an array
>
>
​No, it doesn't. If you want more help from me you will need to supply a
self-contained example. The two-subquery+main version I hinted at below
should give you an array in a single-row/single-column result.​ Try it and
show the failing code if it doesn't. I'll admit I haven't tested it, and
it might not be the best form or most efficient, but it should be workable.

David J.

On Fri, Jun 5, 2015 at 3:38 PM, David G. Johnston <
> david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
>> On Fri, Jun 5, 2015 at 2:00 PM, Bianca Stephani <
>> bianca(dot)stephani(at)gmail(dot)com> wrote:
>>
>>> Thanks for answering. I've already tryied that. When I do what you've
>>> said, i get this:
>>>
>>> [{"array" => "{1,2,3,4,5}"}, {"array" => "6,7,8,9,10}"}...]
>>>
>>> When what i want is this: [1,2,3,4,5,6,7,8,9,19]
>>>
>>>
>> ​Please don't top-post...
>>
>> Nowhere are you mentioning JSON but I presume what you are trying to do
>> involves that...
>>
>> I'm not sure how you expect to the 10 numbers when you only want to
>> concatenate 5 columns...
>>
>> You should share what you have done and the sample data you are using.
>>
>> SELECT array_agg(unnest) AS row_agg FROM (
>> SELECT unnest(col_agg) FROM (
>> SELECT ARRAY[...] AS col_agg FROM ...
>> )));
>>
>> ​That gets you a single array with all the rows and columns in the same
>> dimension.​
>>
>> David J.
>> ​
>>
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Gavin Flower 2015-06-07 23:13:14 Re: Doubt about query
Previous Message Gavin Flower 2015-06-07 23:06:56 Re: Doubt about query