On Wed, 27 Mar 2002, Travis Hoyt wrote:
> Doh! Sorry my code DOES have the FOR in it as does the example in the
> book. Neither works though.
>
> My apologies this was my second attempt w/o the FOR.
>
> Here's what I really have:
>
> CREATE FUNCTION biwklyavg(text, text, text) RETURNS numeric AS '
> DECLARE
> system ALIAS FOR $1;
> startdate ALIAS FOR $2;
> enddate ALIAS FOR $3;
> result numeric;
>
> BEGIN
> result := (select (avg(usr) + avg(sys)) from sardata
> where
> systemid = system and time between startdate and enddate;
> END;
> ' LANGUAGE 'sql';
I think you want plpgsql not sql as the language.
There does appear to be a missing close paren on the result:= thing as
well.