Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 03210475858 for ; Wed, 27 Mar 2002 15:37:26 -0500 (EST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 87DBBD5FA; Wed, 27 Mar 2002 12:37:07 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 7D9945C01; Wed, 27 Mar 2002 12:37:07 -0800 (PST) Date: Wed, 27 Mar 2002 12:37:07 -0800 (PST) From: Stephan Szabo To: Travis Hoyt Cc: PG Explorer , Subject: Re: function error In-Reply-To: Message-ID: <20020327123521.D42156-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200203/366 X-Sequence-Number: 7240 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.