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

From Brian K Boonstra
Subject Aggregate functions with two or more arguments?
Date
Msg-id 832EF96F-D614-11D8-A42D-00039319807C@boonstra.org
Whole thread Raw
In response to Re: determining supported timezones  (Robert Treat <xzilla@users.sourceforge.net>)
Responses Re: Aggregate functions with two or more arguments?
List pgsql-general
Let's say that I want to efficiently compute something like a weighted
standard deviation (the actual formula I have in mind is slightly more
complicated).   The kind of SQL statement I want to have work is
something like

     SELECT weighted_stdev( t.val, t.weight ) FROM target_vals_tbl t
WHERE t.val > 0;


I thought I'd like to write a C function (or more properly a set of two
C functions) into the server side to handle this, and then declare it
as an aggregate using CREATE AGGREGATE.  However, 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.

What should I be doing here?  Is there a way to do this with array
functions instead?



  - Brian K. Boonstra


pgsql-general by date:

Previous
From: David Mitchell
Date:
Subject: Re: Function to get hostname
Next
From: Tom Lane
Date:
Subject: Re: determining supported timezones