Re: an aggregate array function

From: Joe Conway <mail(at)joeconway(dot)com>
To: Merlin Moncure <merlin(dot)moncure(at)rcsonline(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: an aggregate array function
Date: 2003-07-29 14:25:37
Message-ID: 3F2683E1.3030602@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Merlin Moncure wrote:
> What do you think about the other question about an
> 'array creating aggregate', is that a useful contribution?
>

Hmm, either I'm not understanding you, or you're not understanding me ;-)

First, see contrib/intagg.
Second, the following works in 7.4devel:

-- create test data for polymorphic aggregates
create table t(f1 int, f2 float, f3 float);
insert into t values(1,11.1,21.1);
insert into t values(1,11.2,21.2);
insert into t values(1,11.3,21.3);
insert into t values(2,12.1,22.1);
insert into t values(2,12.2,22.2);
insert into t values(2,12.3,22.3);
insert into t values(3,13.1,23.1);
insert into t values(3,13.2,23.2);

CREATE AGGREGATE myagg1
(
BASETYPE = float8,
SFUNC = array_append,
STYPE = float8[],
INITCOND = '{}'
);

CREATE AGGREGATE myagg2
(
BASETYPE = float8[],
SFUNC = array_cat,
STYPE = float8[],
INITCOND = '{}'
);

regression=# select f1, myagg1(f2) from t group by f1;
f1 | myagg1
----+------------------
3 | {13.1,13.2}
2 | {12.1,12.2,12.3}
1 | {11.1,11.2,11.3}
(3 rows)

regression=# select f1, myagg2(array[f2,f3]) from t group by f1;
f1 | myagg2
----+---------------------------------------
3 | {{13.1,23.1},{13.2,23.2}}
2 | {{12.1,22.1},{12.2,22.2},{12.3,22.3}}
1 | {{11.1,21.1},{11.2,21.2},{11.3,21.3}}
(3 rows)

Joe

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Treat 2003-07-29 14:34:56 Re: is 7.3.4 final?
Previous Message Ron Johnson 2003-07-29 14:19:06 Re: concurrent writes