I am trying to execute this function but it is giving me error
ERROR: syntax error at or near "return"
LINE 12: return;
what's wrong with this line ?? I am using Postgres(9.2).
create or replace function conditional_tax(taxPerc decimal(5),minSal decimal(5)) returns SETOF emp as
$body$
declare r emp%rowtype;
begin
For r in select * from emp where salary > minSal
Loop
r.salary = r.salary - (r.salary * taxPerc /100) ;
return next r;
End Loop
return;
end
$body$
Language 'plpgsql';
asked Sep 13, 2013 at 4:00
Rakesh Chouhan
1,24013 silver badges29 bronze badges
2 Answers 2
There's nothing wrong with that line. However, there is something wrong with the previous line.
You're meant to terminate the end loop with a semi-colon ;. The syntax chart is:
[ <<label>> ]
LOOP
statements
END LOOP [ label ];
answered Sep 13, 2013 at 4:09
paxdiablo
889k243 gold badges1.6k silver badges2k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
This is much simpler. Just plain SQL. SQL Fiddle
create or replace function conditional_tax(
taxPerc decimal(5),
minSal decimal(5)
) returns SETOF decimal(5) as $body$
select salary * (1 - taxPerc / 100) as salary
from emp
where salary > minSal
;
$body$ language sql;
answered Sep 14, 2013 at 12:00
Clodoaldo Neto
127k30 gold badges251 silver badges274 bronze badges