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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.