if condition on postgress function
so I want to check if user has enough balance like
~
declare
after_balance numeric;
begin
select balance
into after_balance
from profiles
where id = new.owner;
if (after_balance + new.price) < 0 then
raise exception 'You dnt have enough balance';
end if;
update balance from profiles SET after_balance WHERE id = new.owner;
return new;
end;
~
but cant do that because near 'end' ??
~
declare
after_balance numeric;
begin
select balance
into after_balance
from profiles
where id = new.owner;
if (after_balance + new.price) < 0 then
raise exception 'You dnt have enough balance';
end if;
update balance from profiles SET after_balance WHERE id = new.owner;
return new;
end;
~
but cant do that because near 'end' ??

