Thread: Writing your own aggregate functions

Writing your own aggregate functions

From
Bastiaan Olij
Date:
Hiya,

I was wondering if it is possible in Postgres to write an aggregate
function?

So say if I wanted to execute the following statement:

select Column1, sum(Column2), myFunction(Column3)
from MyTable
group by Column1

Could I implement myFunction as a stored function and how would I go
about doing so?

Cheers,

Bas


Re: Writing your own aggregate functions

From
Merlin Moncure
Date:
On Tue, Mar 5, 2013 at 9:44 PM, Bastiaan Olij <bastiaan@basenlily.me> wrote:
> Hiya,
>
> I was wondering if it is possible in Postgres to write an aggregate
> function?
>
> So say if I wanted to execute the following statement:
>
> select Column1, sum(Column2), myFunction(Column3)
> from MyTable
> group by Column1
>
> Could I implement myFunction as a stored function and how would I go
> about doing so?

it's trivial (and an extremely underutlized feature):
http://www.postgresql.org/docs/9.2/static/xaggr.html

merlin