Re: requesting features in PostgreSQL - Mailing list pgsql-general

From Jeff Davis
Subject Re: requesting features in PostgreSQL
Date
Msg-id 200204270819.BAA18541@smtp.ucsd.edu
Whole thread Raw
In response to Re: requesting features in PostgreSQL  (Andrew Gould <andrewgould@yahoo.com>)
Responses Re: requesting features in PostgreSQL
List pgsql-general
I decided to use your problem as a little exercize for myself, so I came up
with a working aggregate for gmean. I posted the code below. I wrote it in
plpgsql. It's possible the "a1" function (the main part of the aggregate)
won't be the bottleneck for performance. You could probably translate to C,
and you can probably solve the problem more gracefully than I, but I have
working code. I couldn't think of what else to use as a state type, so I just
used a two-element array of floats. The first element holds the running
product (i.e. 1*2*3*9) and the second holds the number of records visited (4).

I would appreciate it if you (or anyone else) would post (or direct email)
what changes you make for efficiency, including if you write a c function for
a1 (a2 doesn't really need a C func unless you really want, since it should
only be called once per aggregation). I could probably help you translate to
C if you'd like, but first I'd like to make sure I have the most efficient
algorithm.

Regards,
    Jeff

______________________________________
create function a1f(float[2]) returns float as '
BEGIN
return ($1[1]^(1/($1[2])));
END;
' language 'plpgsql';

create function a1(float[2],float) returns float[2] as '
DECLARE
ret float[2];
BEGIN
ret := ''{'' || (($1[1]) * ($2)) || '','' || (($1[2]) + 1) || ''}'';
RETURN ret;
END;
' language 'plpgsql';

create aggregate a2
(basetype=float,sfunc=a1,stype=float[],finalfunc=a1f,initcond='{1.0,0.0}');


pgsql-general by date:

Previous
From: Jeffrey Baker
Date:
Subject: Re: intel vs amd benchmark for pg server part 2
Next
From: "Hegyvari Krisztian"
Date:
Subject: creating a dump