I have a table with a lot of rows and I have changed the function associated with the trigger in insert or update events. This function makes calculations to update columns with conditional logic according to the values in two or more cells, so an single update statement would not be useful.
So, which SQL statement can I use to re-execute the trigger and update all the rows?
Thank you.
You have to update a column with exactly the same value. Of course it depends on the conditions for trigger. For instance:
UPDATE table
SET columnX = columnX;
Any way, as a best-practices for this cases I usually have and associated function in which I can run something like (not sure if works for progresql):
BEGIN
for c in (select column_id from table)
loop
function_on_trigger(c.column_id);
end loop;
END;
/
In response to FerranB's answer, the correct way to run the function in Postgres would be the following:
SELECT function_on_trigger(column_id) FROM table;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With