well i have looked for a lot of places on the internet for the cause of the mysql error #1442
which says
Can't update table 'unlucky_table' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
some say that this is a bug in mysql or a feature that it doesnt provide.
Some claim that this is due to recursive behavior when you insert a record mysql is doing some lock stuff. you can't insert/update/delete rows of the same table where you insert.. because then the trigger would called again and again.. ending up in a recursion
now i cant understand why this is recursive. i have a case in which i have 2 tables table1
and table2
and i run an sql query as
update table1 set avail = 0 where id in (select id from table2 where duration < now() - interval 2 hour);
now i have an after update trigger
on table1
as
CREATE TRIGGER trig_table1 AFTER UPDATE ON table1
FOR EACH ROW begin
if old.avail=1 and new.avail=0 then
delete from table2 where id=new.id;
end if;
now when i execute the update query i get a 1442 error. whats recursive in this case?
is this error a lack of feature in mysql?
OR
does this have to do with how mysql executes queries?
OR
is there something logically wrong with executing such queries?