From: | Jeff Davis <list-pgsql-general(at)empires(dot)org> |
---|---|
To: | Andrew Gould <andrewgould(at)yahoo(dot)com> |
Cc: | Postgres Mailing List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: requesting features in PostgreSQL |
Date: | 2002-04-27 08:17:39 |
Message-ID: | 200204270819.BAA18541@smtp.ucsd.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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}');
From | Date | Subject | |
---|---|---|---|
Next Message | Hegyvari Krisztian | 2002-04-27 09:16:08 | creating a dump |
Previous Message | Jeffrey Baker | 2002-04-27 06:47:21 | Re: intel vs amd benchmark for pg server part 2 |