Bug #40371 Triggerfunction can't use table where the trigger occured
Submitted: 28 Oct 2008 14:08 Modified: 15 Dec 2010 10:30
Reporter: Frank Mussmann Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S4 (Feature request)
Version:5.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: stored procedure, trigger

[28 Oct 2008 14:08] Frank Mussmann
Description:
As mentioned in F.1. Restrictions on Stored Routines and Triggers
"Within a stored function or trigger, it is not permitted to modify a table that is already being used (for reading or writing) by the statement that invoked the function or trigger."
But this would be a good detail for working with triggers.
When I got a Table "wtf" like this:
n   int     <-- PK
ttt varchar(200)
ttt2 varchar(10) and ttt2 represents left(ttt,10), it would be great to have a trigger like this:
CREATE TRIGGER t_insert_after 
FOR EACH ROW BEGIN
 update wtf set ttt2=left(ttt) where n=NEW.n;
END

This would be great for big bulk inserts.

How to repeat:
-----

Suggested fix:
Within a stored function or trigger, it is not permitted to modify a table that is already being used (for reading or writing) by the statement that invoked the function or trigger.
BUT:
Updates are OK when Inserting/Updates on other fields which are invoked by the Trigger-function
NO UPDATES while DELETE !!!
[15 Dec 2010 10:30] Valeriy Kravchuk
This is a duplicate of bug #29542.