Re: array question

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

That's exactly what I needed. Thanks very much!

-Whit

On Fri, Oct 9, 2009 at 12:29 PM, Raymond O'Donnell <rod(at)iol(dot)ie> wrote:
> On 09/10/2009 17:17, Whit Armstrong wrote:
>> 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)
>
> Someone (Alvaro?) once posted a really handy aggregate which ought to do
> what you want:
>
>  CREATE AGGREGATE array_accum(anyelement) (
>    SFUNC=array_append,
>    STYPE=anyarray,
>    INITCOND='{}'
>  );
>
> And then you'd call it like so:
>
>  select agent_name, array_accum(myval) from ary_values
>    group by agent_name;
>
>
> I hope that helps.
>
> Ray.
>
>
>
> ------------------------------------------------------------------
> Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
> rod(at)iol(dot)ie
> Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
> ------------------------------------------------------------------
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Ribe 2009-10-09 16:46:39 Integer range?
Previous Message Bruce Momjian 2009-10-09 16:29:46 Re: numeric field overflow