pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to split an array into columns
4+ messages / 4 participants
[nested] [flat]
* How to split an array into columns
@ 2018-08-24 09:01 a <372660931@qq.com>
0 siblings, 2 replies; 4+ messages in thread
From: a @ 2018-08-24 09:01 UTC (permalink / raw)
To: pgsql-general
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().
Thank you so much!
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How to split an array into columns
@ 2018-08-24 09:09 Thomas Kellerer <spam_eater@gmx.net>
parent: a <372660931@qq.com>
1 sibling, 1 reply; 4+ messages in thread
From: Thomas Kellerer @ 2018-08-24 09:09 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
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.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How to split an array into columns
@ 2018-08-24 13:41 Tom Lane <tgl@sss.pgh.pa.us>
parent: Thomas Kellerer <spam_eater@gmx.net>
0 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2018-08-24 13:41 UTC (permalink / raw)
To: Thomas Kellerer <spam_eater@gmx.net>; +Cc: pgsql-general@lists.postgresql.org
Thomas Kellerer <spam_eater@gmx.net> writes:
> Maybe I am missing something, but:
> select id, data[1], data[2]
> from the_table;
> will work just fine.
If the arrays are of varying length, unnest() might be what the OP
is looking for.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How to split an array into columns
@ 2018-08-24 16:54 Paul A Jungwirth <pj@illuminatedcomputing.com>
parent: a <372660931@qq.com>
1 sibling, 0 replies; 4+ messages in thread
From: Paul A Jungwirth @ 2018-08-24 16:54 UTC (permalink / raw)
To: a <372660931@qq.com>; +Cc: pgsql-general
On Fri, Aug 24, 2018 at 2:01 AM, a <372660931@qq.com> wrote:
>
> Say if I have an float8 array:
>
> id| data
> --|---------------
> 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().
Is this something that would help you?:
https://github.com/pjungwir/aggs_for_vecs
(also on pgxn: https://pgxn.org/dist/aggs_for_vecs)
It would let you say `SELECT vec_to_sum(data)` and get `{3,6}`.
Paul
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2018-08-24 16:54 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-08-24 09:01 How to split an array into columns a <372660931@qq.com>
2018-08-24 09:09 ` Thomas Kellerer <spam_eater@gmx.net>
2018-08-24 13:41 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-08-24 16:54 ` Paul A Jungwirth <pj@illuminatedcomputing.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox