Re: function error

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Travis Hoyt <thoyt(at)npc(dot)net>
Cc: PG Explorer <pgmail(at)pgexplorer(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: function error
Date: 2002-03-27 20:37:07
Message-ID: 20020327123521.D42156-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rudi Starcevic 2002-03-28 01:47:52 psql and password
Previous Message Jan Wieck 2002-03-27 20:25:59 Re: function error