Re: function error - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: function error
Date
Msg-id 20020327123521.D42156-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Re: function error  ("Travis Hoyt" <thoyt@npc.net>)
List pgsql-sql
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.




pgsql-sql by date:

Previous
From: Jan Wieck
Date:
Subject: Re: function error
Next
From: Rudi Starcevic
Date:
Subject: psql and password