Have to write a function which returns the sum of all the square between 2 user input numbers. Here is what i have written but cant seem to make it work. E.g. sumAll(2, 5) must give the result 54 .
CREATE OR REPLACE FUNCTION SumAll(integer,integer) RETURNS integer as $$
DECLARE
num1 ALIAS for $1;
num2 ALIAS for $2;
ret_sum integer;
sum1 integer;
BEGIN
for i in num1..num2 LOOP
sum1:=i*i;
ret_sum=ret_sum+sum1;
END LOOP;
return ret_sum;
END
$$ language 'plpgsql';
it doesnt work. what am i doing wrong?