We help IT Professionals succeed at work.
Get Started

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

457 Views
Last Modified: 2012-06-21
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`;

Open in new window


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.

Open in new window


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?
Comment
Watch Question
Top Expert 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE