Migrating the following function from 8.3.9 to 9.1.7 throws the error:
SELECT easy_pay(606,1);
ERROR: syntax error at or near "."
LINE 1: SELECT user.esbalance < amount
^
QUERY: SELECT user.esbalance < amount
CONTEXT: PL/pgSQL function "easy_pay" line 19 at IF
Code:
CREATE OR REPLACE FUNCTION public.easy_pay(integer, integer)
RETURNS integer
LANGUAGE plpgsql
AS $function$DECLARE
user_id ALIAS FOR $1;
amount ALIAS FOR $2;
user record;
mg record;
newbalance float;
BEGIN
SELECT INTO user es.balance as esbalance
from
easy_users es
where
es.usid = user_id;
IF NOT FOUND THEN
RAISE EXCEPTION 'Cannot find user';
return -2;
END IF;
IF user.esbalance < amount THEN
return -1;
END IF;
newbalance := user.esbalance - amount;
UPDATE easy_users SET balance = newbalance
WHERE usid = user_id;
return 1;
END;$function$
Language 'plpgsql' is already installed in the database..
Any help will be appreciated!