Re: How to split an array into columns

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: How to split an array into columns
Date: 2018-08-24 09:09:58
Message-ID: e61c1c80-19e4-6403-a4d5-f9b18c50988d@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

a schrieb am 24.08.2018 um 11:01:
> Say if I have an float8 array:
>
> id| data
> --|---------------
> a | {1,2}
> b | {2,4}
>
> If I could using query to make it looks like this:
>
> id| data[1] | data[2]
> --|----------|-----------
> a | 1 | 2
> b | 2 | 4
>
> Since I would have around 200,000 rows, I would prefer it having
> enough capacity to carry out the calculation such as sum().

Maybe I am missing something, but:

select id, data[1], data[2]
from the_table;

will work just fine.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Naveen Dabas 2018-08-24 10:38:55 Re: pg_sample
Previous Message a 2018-08-24 09:01:53 How to split an array into columns