Re: Aggregate functions with two or more arguments?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mike Mascari <mascarm(at)mascari(dot)com>
Cc: Brian K Boonstra <postgresql(at)boonstra(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Aggregate functions with two or more arguments?
Date: 2004-07-15 14:02:51
Message-ID: 20454.1089900171@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)mascari(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-07-15 14:24:19 Re: tcl and rpms for rhel3
Previous Message Jeff Eckermann 2004-07-15 13:45:19 Re: Getting started with replication