nentwined20 Jan 2005
create or replace function voteaverage(int4) returns float as '
DECLARE
myavg float8;
BEGIN
myavg = 5+(float8(((avg(v.value)-5)))*(1/(1+exp(float8(3-count(v.value)/3))))) from votes v, poemranker_poems p WHERE v.poemid = $1 and v.poemid = p.id AND v.stamp > p.lastmod;
if myavg IS NULL THEN
return 5;
end if;
return myavg;
END;
' language 'plpgsql';