I have an update statement, nested in an update trigger:
CREATE TRIGGER "BAD_RECURSIVE_TRIGGER"
AFTER UPDATE ON "MYTABLE"
REFERENCING NEW AS NEW_ROW
FOR EACH ROW
WHEN (NEW_ROW.ORDER IS NOT NULL)
BEGIN ATOMIC
IF <SOMECONDITION> THEN
UPDATE "MYTABLE" SET ORDER=ORDER+1 // This "update" fires the recursion.
WHERE <OTHERCONDITION>
END IF;
END;
I want to prevent the recursive execution of the trigger, this is on DB2 (v9.7), I've seen similar questions for SQL-Server and ORACLE databases:
Prevent recursive trigger in PostgreSQL
How do I prevent a database trigger from recursing?
But I can't find a way to prevent this over DB2. Is there a way to prevent a recursive trigger call over DB2?
AFTER UPDATE? What happens if the trigger happens before the actual update, and modifiesORDERat that point? And I would have assumed that you only want to update the 'current' row, but that statement is going to update the entire table... Alternatively, only update ifORDERhasn't changed from it's current value (if the new value is the same as the old, in-table value).