Hola a todos, tengo un problemilla con un trigger:
Código:
create table bookmarks(
id integer unsigned not null auto_increment,
name varchar(50) not null,
parent integer unsigned,
childCount integer unsigned not null,
primary key(id)
);
delimiter |
create trigger updateChildCount after insert on bookmarks
for each row
begin
if new.parent is not null then
update bookmarks set childCount=childCount+1 where id = NEW.parent;
end if;
end;
|
delimiter ;
Básicamente tengo una jerarquía de bookmarks, en donde el campo 'parent' indica el bookmark padre, y 'childCount' indica cuántos hijos tiene cada bookmark.
El trigger básicamente incrementa 'childCount' del padre al insertar un nuevo bookmark. El caso es que MySQL se queja porque dice que no puedo hacer un update en la misma tabla que invoca el trigger:
Cita: ERROR 1442 (HY000): Can't update table 'bookmarks' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
¿Alguna idea de cómo hacer esto?