Aggregate functions with two or more arguments?

From: Brian K Boonstra <postgresql(at)boonstra(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Aggregate functions with two or more arguments?
Date: 2004-07-15 04:07:39
Message-ID: 832EF96F-D614-11D8-A42D-00039319807C@boonstra.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-07-15 04:31:24 Re: determining supported timezones
Previous Message David Mitchell 2004-07-15 03:57:33 Re: Function to get hostname