使用INSERT AND DELETE保存MySQL事件时出现语法错误

时间:2016-08-30 23:33:44

标签: mysql mysql-event

我创建的EVENT基本上做了两件事:

  1. SELECT超过30天的行INSERT进入achieve表。
  2. DELETE trends表中超过30天的行。
  3. 我分别测试了两个脚本,它们都工作正常,但是在将它们放入EVENT时出现了语法错误。

    如果我只在活动正文中使用INSERT INTODELETE脚本,则会保存正常。

    脚本是:

    CREATE DEFINER=`root`@`localhost` 
        EVENT `trend_decayer` ON SCHEDULE EVERY 1 DAY 
        STARTS '2016-08-30 00:00:00' ON COMPLETION NOT PRESERVE ENABLE 
        COMMENT 'Decay trends that are older than 30 days' 
    DO
    INSERT INTO `achieve` 
        SELECT *, FROM_UNIXTIME(`trends`.`timestamp`) AS `datetime` 
        FROM `trends`
        WHERE `t`.`timestamp` < UNIX_TIMESTAMP(CAST(DATE_SUB(NOW(), INTERVAL 30 DAY) AS DATETIME)) 
        ORDER BY `datetime` DESC;
    DELETE 
        FROM `trends` 
        WHERE `timestamp` < UNIX_TIMESTAMP(CAST(DATE_SUB(NOW() , INTERVAL 30 DAY) AS DATETIME));
    

    错误消息是:

    MySQL said: #1064 - You have an error in your SQL syntax; 
    check the manual that corresponds to your MySQL server version for the right syntax to use near 
    'INTO `achieve` 
        SELECT *, FROM_UNIXTIME(`timestamp`) AS `datetime` FR' at line 2`
    

0 个答案:

没有答案