【发布时间】:2018-06-05 20:32:42
【问题描述】:
我正在尝试从我的 AWS RDS MySQL 实例中分块删除大量数据。我正在尝试修改此 link 中的代码,但我遇到了无法修复的语法错误。
错误:
SQL Error (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 'main1: LOOP
SELECT @z := operation_id FROM operations_test WHERE operation_id' at line 2
代码:
SET @apt = 'DTW';
SET @a = (SELECT MIN(operation_id) FROM operations_test);
BEGIN
main1: LOOP
SELECT @z := operation_id FROM operations_test WHERE operation_id >= @a ORDER BY operation_id LIMIT 1000,1;
IF @z IS NULL THEN
LEAVE main1; -- last chunk
END IF;
DELETE operations_test, profiles_test FROM profiles_test LEFT JOIN operations_test ON operations_test.operation_id=profiles_test.operation_id WHERE operations_test.airport_id = @apt
AND operations_test.operation_id >= @a
AND operations_test.operation_id < @z;
DELETE operations_test FROM operations_test WHERE airport_id = @apt
AND operation_id >= @a
AND operation_id < @z;
SET @a = @z;
SLEEP 1; -- be a nice guy, especially in replication
END LOOP main1;
END;
# Last chunk:
DELETE operations_test, profiles_test FROM profiles_test LEFT JOIN operations_test ON operations_test.operation_id=profiles_test.operation_id WHERE operations_test.airport_id = @apt
AND id >= @a;
DELETE operations_test FROM operations_test WHERE airport_id = @apt
AND id >= @a;
【问题讨论】:
-
您可能需要在声明匿名块之前设置不同的分隔符。类似
DELIMITER $$ BEGIN ... END; DELIMITER ;
标签: mysql sql-delete