Re: Aggregate functions with two or more arguments? - Mailing list pgsql-general

From Tom Lane
Subject Re: Aggregate functions with two or more arguments?
Date
Msg-id 20454.1089900171@sss.pgh.pa.us
Whole thread Raw
In response to Re: Aggregate functions with two or more arguments?  (Mike Mascari <mascarm@mascari.com>)
List pgsql-general
> Brian K Boonstra wrote:
>> ... aggregate functions
>> appear to want just a single argument, so I feel like either I am on the
>> wrong track, or I have run into a limitation of postgresql.

Sooner or later someone should fix aggregates to allow multiple inputs.
There was once a restriction in the catalog layout that prevented it,
but that's been gone since 7.3 or so.  I think the only part that would
be even slightly difficult is supporting DISTINCT aggregates.

Mike Mascari <mascarm@mascari.com> writes:
> I'm not sure what the most elegant solution is, but when I've
> encountered this scenario in the past, I created a custom type for
> the aggregate.

This will actually be quite painless in 7.5, since you can just use a
composite type.  It'd go something like

create type mytype as (f1 int, f2 text);
... create aggregate accepting mytype as input ...
select myagg(row(x,y)) from table;

No need for any C code.

            regards, tom lane

pgsql-general by date:

Previous
From: Jeff Eckermann
Date:
Subject: Re: Getting started with replication
Next
From: Tom Lane
Date:
Subject: Re: tcl and rpms for rhel3