Re: Split the result of a query in 2 rows

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Split the result of a query in 2 rows
Date: 2015-03-04 18:56:14
Message-ID: CAKFQuwZZdRf3tsmOgDQhMV0B5_-H2d9m6Nb2jnV_vFeoHO2O3w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, Mar 4, 2015 at 11:53 AM, Frank Pinto [via PostgreSQL] <
ml-node+s1045698n5840504h48(at)n5(dot)nabble(dot)com> wrote:

> So:
> If the original result set returned 1 row with 2 columns the new solution
> would return 2 rows with 1 column?
> If the original result set returned 100 row with 3 columns the new
> solution would return 300 rows (1 row gets turned into 3 rows * 100 rows =
> 300)?
>
> I would use unnest
> <http://blog.lerner.co.il/turning-postgresql-arrays-rows-unnest/>.
> Something like this (untested):
> ​
>
>

> WITH temp_table AS (
> SELECT ARRAY(SELECT field1, field2 FROM tbl_table ORDER BY field1) AS
> prepared_fields;
> )
> SELECT UNNEST(prepared_fields) FROM temp_table;
>
>
​​I would suggest you test this...

David J.​

--
View this message in context: http://postgresql.nabble.com/Split-the-result-of-a-query-in-2-rows-tp5840497p5840505.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message David G Johnston 2015-03-04 19:00:48 Re: Split the result of a query in 2 rows
Previous Message Frank Pinto 2015-03-04 18:53:03 Re: Split the result of a query in 2 rows