troubleshooting Question

Is it possible to use a trigger to delete data from the table that the trigger is based upon?

Avatar of Richard Quadling
Richard QuadlingFlag for United Kingdom of Great Britain and Northern Ireland asked on
DatabasesMySQL ServerSQL
5 Comments1 Solution459 ViewsLast Modified:
Hi.

I have a table which acts as a short term cache of some status information. Each row in the table holds the number of images to process and the number of processed images.

I have multiple servers writing to this table (Amazon EC2 setup).

When all the images are processed, I want to delete the row.

So, conventionally,
DELETE FROM
 `datafeeds`.`im_retailerimageprocessing`
WHERE
 `ImagesToProcess` = `ImagesProcessed`;

Putting that in a AFTER UPDATE ON trigger, I get an error upon execution :
Error Code: 1142. Can't update table 'im_retailerimageprocessing' in stored function/trigger because it is already used by statement which invoked this function/trigger.

For me, as I'm using it in an AFTER statement, there should be no conflict. But, obviously, I'm wrong and I don't know how to achieve the desired result.

I don't want to modify the app as it is very simple and just "ticks" a box when it has done its job. The scheduler/dispatcher deals with creating the threads and I want to use the DB to keep all the DB uptodate.

What am I missing?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros