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


---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to