Can't see what's wrong with this function?

Started by Bjørn T Johansenover 19 years ago2 messagesgeneral
Jump to latest
#1Bjørn T Johansen
btj@havleik.no

I am trying to create a function but I don't get further than this and something is already wrong...
The function so far look like this..:

CREATE OR REPLACE FUNCTION getNettoHastighet (INTEGER) RETURNS INTEGER AS '
DECLARE
ordreid_val ALIAS FOR $1;
tmprec RECORD;
opplag integer;
total bigint;
total_hour float;
hastighet integer;
BEGIN
select into tmprec (extract(epoch from sum(Til - Fra)) * 1000.0) as total from Log_stop where OrdreID = ordreid_val and StopType = 1;
total := tmprec.total;
return 0;
END;
' LANGUAGE 'plpgsql';

I get the following error if I try to create the function..:

[Error Code: 0, SQL State: 42601] ERROR: syntax error at or near "$1"

Any hints on what's wrong?

Regards,

BTJ

--
-----------------------------------------------------------------------------------------------
Bjørn T Johansen

btj@havleik.no
-----------------------------------------------------------------------------------------------
Someone wrote:
"I understand that if you play a Windows CD backwards you hear strange Satanic messages"
To which someone replied:
"It's even worse than that; play it forwards and it installs Windows"
-----------------------------------------------------------------------------------------------

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bjørn T Johansen (#1)
Re: Can't see what's wrong with this function?

=?ISO-8859-1?Q?Bj=F8rn?= T Johansen <btj@havleik.no> writes:

I am trying to create a function but I don't get further than this and something is already wrong...
The function so far look like this..:

CREATE OR REPLACE FUNCTION getNettoHastighet (INTEGER) RETURNS INTEGER AS '
DECLARE
total bigint;
BEGIN
select into tmprec (extract(epoch from sum(Til - Fra)) * 1000.0) as total from Log_stop where OrdreID = ordreid_val and StopType = 1;

Don't use plpgsql variable names that conflict with names you use in
your queries. In this case it's trying to replace "AS total" with
a reference to that plpgsql variable named total.

regards, tom lane