Is there a decent way to delay execution of mysql trigger?
WHILE @condition = 0
sleep for awhile
insert into some_table values(NEW.value1, NEW.value2);
Since MySQL 5.0.12, you can do this:
SELECT SLEEP(<seconds>);
The seconds parameter can be in a fraction of a second like .5.
DO SLEEP(<seconds>);
is better. There is no reason to just run SELECT
statements inside triggers without needing the result set.
If you really want to do this you need to do it like here:
SET @nothing = (SELECT SLEEP(<seconds>));
But I recommend to use DO
. And don't forget that a trigger is just a single statement per default. If you have more then 1 statement in your trigger you need to use BEGIN
/END
:
BEGIN
DO SLEEP(<seconds>);
UPDATE ...;
END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With