problem with PL/pgSQL

From: "Tiberiu Craciun" <tiberiu(at)akela(dot)ro>
To: <pgsql-sql(at)hub(dot)org>
Subject: problem with PL/pgSQL
Date: 1999-06-24 10:21:54
Message-ID: 010101bebe2b$62327e20$0201a8c0@tibi.akela.ro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a table and a function defined like that :

create table trafic (
statie text,
traf_in int8 default 0,
traf_out int8 default 0
);

create function addtrafic (text, int8, int2) returns int2 as '
declare
statia alias for $1 ;
traficul alias for $2 ;
directia alias for $3 ;
begin
select * from trafic where statie= $1;
if not found then
insert into trafic (statie) values( $1 );
endif;
if $3 < 1 then
update trafic set traf_in=traf_in+ $2 where statie= $1;
else
update trafic set traf_out=traf_out+ $2 where statie= $1;
endif;
return $3 ;
end;
' language 'plpgsql';

when I run this SQL :

select addtrafic('station1',10,0) as test;

I got an error like that :

NOTICE: plpgsql: ERROR during compile of addtrafic near line 20
ERROR: parse error at or near ";"

and i don't know what is wrong, can someone help me ?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Eric BASIER 1999-06-24 11:51:59 Re: [SQL] problem with PL/pgSQL
Previous Message Chris Bitmead 1999-06-24 07:16:23 Nested structures