| From: | Bill Eaton <wpeaton(at)adelphia(dot)net> | 
|---|---|
| To: | pgsql-general(at)postgresql(dot)org | 
| Subject: | user defined aggregate with multiple arguments | 
| Date: | 2006-10-12 05:23:27 | 
| Message-ID: | 452DD14F.9000107@adelphia.net | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
I have a need to create some statistical functions in PostgreSQL that 
will take multiple "column" arguments and return multiple values.
A good example would be a least squares fit of a line through a set of 
(x,y) points. In this case, I would want the function to accept two 
"columns" of data (i.e. x data and y data) as arguments and return two 
parameters: the slope and intercept of a line.
The slope is given by 
   [sum(x^2)*sum(y) - sum(x)*sum*x*y)] / [M*sum(x^2) -(sum(x))^2]
It's not *that* complicated, but it's not that easy to remember either. 
And if you're already doing a lot of work to tease out the x and y 
points from various tables, it simplifies your query if you can do a 
function call.
I can't tell from what have read about user defined functions and user 
defined aggregates whether this kind of function is possible.
Bill Eaton
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bill Eaton | 2006-10-12 05:41:04 | Re: user defined aggregate with multiple arguments | 
| Previous Message | alexei.vladishev | 2006-10-12 05:17:58 | Re: more anti-postgresql FUD |