I have a super simple table
id, entries, max_capacity, factor So we have ex 500 max capacity and 250 entries and it should be 50 (50% full) easy right? Problem is when I update the entries I want the factor to auto update as well, so I have done the function:
create function myUp() returns trigger as $$
begin
update myTable
set factor=round(100*(entries/max_capacity),0);
end;
$$ language plpgsql;
and the trigger
create trigger myUp
after insert or update on myTable
for each row
execute procedure myUp();
and I get a new trigger function and running an update example
update myTable
set entries=500
where id=1;
Where I update the entries on one of the rows and I get the ERROR stack depth limit exceeded CONTEXT update myTable....
Why do I get this? Do I have to set the entries for all of the rows for it to work? I have no clue why it is not working. I want the after because I cant calculate the value before I inserted the new entries values.