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-05 17:40:01
Message-ID: CAKFQuwZG4YxxxpJCvqPrd2nJRp=fxTPz5T55mK_y1s=psgsAzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Jun 5, 2015 at 1:25 PM, 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? :|
>
>
​Do you have a particular output column type you'd like the data to be in?​

​SELECT ARRAY[col1, col2, col3, col4, col5]::integer[] FROM tbl

David J.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message lmanorders 2015-06-05 17:55:36 Windows Install Error getlocales.exe
Previous Message Bianca Stephani 2015-06-05 17:25:16 Doubt about query