Re: intagg

From: Arjen Nienhuis <a(dot)g(dot)nienhuis(at)gmail(dot)com>
To: Andrew Bartley <ambartley(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: intagg
Date: 2013-06-20 19:37:15
Message-ID: CAG6W84KcATxUP6GEWx_=Zu7cVZpvp-BjyKfSaoLmLWdGBWMwow@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 20, 2013 at 12:22 AM, Andrew Bartley <ambartley(at)gmail(dot)com> wrote:
> Sorry that should be aggregate int_array_aggregate not function
>
>
> On 20 June 2013 08:16, Andrew Bartley <ambartley(at)gmail(dot)com> wrote:
>>
>> Hi All,
>>
>> I am trying to use the intagg extension. in 9.1.9
>>
>> I have created the extension as such "CREATE EXTENSION intagg"
>>
>> Then tried to use the function int_array_aggregate.
>>
>> Returns this message
>>
>> function int_array_aggregate(integer[]) does not exist
>>
>> select int_array_aggregate(transactions) from x
>>
>> x being
>>
>> create table x (transactions int4[]);
>>
>> Can anyone please advise..
>>
>> Thanks
>>
>> Andrew Bartley
>
>

int_array_aggregate or (array_agg) needs int as input not int[]. You
can unnest first:

=> INSERT INTO x VALUES ('{4,5,6}');
INSERT 0 1
=> INSERT INTO x VALUES ('{1,20,30}');
INSERT 0 1
=> SELECT unnest(transactions) FROM x;
unnest
--------
4
5
6
1
20
30
(6 rows)

=> SELECT array_agg(i) FROM (SELECT unnest(transactions) from x) AS j(i);
array_agg
-----------------
{4,5,6,1,20,30}
(1 row)

=> SELECT array_agg(i ORDER BY i) FROM (SELECT unnest(transactions)
from x) AS j(i);
array_agg
-----------------
{1,4,5,6,20,30}
(1 row)

=> SELECT array_agg(i ORDER BY i) FROM (SELECT unnest(transactions)
from x) AS j(i) GROUP BY i % 2;
array_agg
-------------
{4,6,20,30}
{1,5}
(2 rows)

In response to

  • Re: intagg at 2013-06-19 22:22:27 from Andrew Bartley

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2013-06-20 19:40:43 Re: intagg
Previous Message David Johnston 2013-06-20 19:29:38 Re: Problem with left join when moving a column to another table