array question

From: Whit Armstrong <armstrong(dot)whit(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: array question
Date: 2009-10-09 16:17:39
Message-ID: 8ec76080910090917oef31173jfdf4d789f7c7040@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is there any easy way to get this data:

kls_dev=# select * from ary_values;
agent_name | myval
------------+-------
a | 1
a | 2
a | 3
b | 4
b | 5
b | 6
(6 rows)

to look like this:

kls_dev=# select * from ary_test;
agent_name | vals
------------+---------
a | {1,2,3}
b | {4,5,6}
(2 rows)

In other words, I would like to group by 'agent_name' and then convert
all the 'myvals' associated w/ that agent_name into an array.

I tried a few simple things like this:
kls_dev=# select array_append(myval) from ary_values group by agent_name;

but no luck so far.

Thanks,
Whit

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Kretschmer 2009-10-09 16:18:02 Re: what is the best way to concat fields that may contain null as if they were empty strings
Previous Message Andrew Gould 2009-10-09 16:06:37 Re: interface for "non-SQL people"