希望每个人都很好。
我正在尝试将数据从一个表格移动到另一个表格,但我得到了以下错误,这实际上让我感到疯狂,因为我无法看到它为什么不能工作的任何逻辑原因 - 事实上,我在过去运行相同的查询完全没问题!
错误1442(HY000):无法更新表格' bb_events'在存储的函数/触发器中,因为它已被调用此存储函数/触发器的语句使用。
我正在运行的查询是:
INSERT INTO `bb_events` (
`account_id`,
`device_id`,
`timestamp`,
`status_code`,
`latitude`,
`longitude`,
`speed`,
`heading`,
`odometer`,
`address`,
`street`,
`city`,
`state`,
`postcode`,
`country`,
`geozone_id`,
`battery_volts`,
`driver_id`,
`engine_time`,
`idle_time`,
`work_time`)
SELECT
`accountID` AS `account_id`,
`deviceID` AS `device_id`,
`timestamp` AS `timestamp`,
`statusCode` AS `status_code`,
`latitude`,
`longitude`,
`speedKPH`*0.621371192 AS `speed`,
`heading`,
`odometerKM`*0.621371192 AS `odometer`,
`address`,
`streetAddress` AS `street`,
`city`,
`stateProvince` AS `state`,
`postalCode` AS `postcode`,
`country`,
`geozoneID` AS `geozone_id`,
`batteryVolts` AS `battery_volts`,
`driverID` AS `driver_id`,
`engineHours`*3600 AS `engine_time`,
`idleHours`*3600 AS `idle_time`,
`workHours`*3600 AS `work_time`
FROM
`EventData`;
在bb_events
表格中,我有一个触发设置,如下所示: -
DELIMITER $$
DROP TRIGGER /*!50032 IF EXISTS */ `event_insert_after` $$
CREATE TRIGGER `event_insert_after` AFTER INSERT ON `bb_events`
FOR EACH ROW
BEGIN
UPDATE `bb_device` SET `latitude` = NEW.`latitude`, `longitude` = NEW.`longitude`, `status_code` = NEW.`status_code`, `timestamp` = NEW.`timestamp`, `speed` = NEW.`speed`, `driver_id` = NEW.`driver_id`, `heading` = NEW.`heading` WHERE `account_id` = NEW.`account_id` AND `device_id` = NEW.`device_id`;
IF NEW.`status_code` = 62465 THEN
INSERT INTO `bb_journey` (`account_id`, `device_id`, `start_timestamp`, `start_street`, `start_city`, `start_state`, `start_country`, `start_latitude`, `start_longitude`, `start_geozone`, `start_odometer`) VALUES (NEW.`account_id`, NEW.`device_id`, NEW.`timestamp`, NEW.`street`, NEW.`city`, NEW.`state`, NEW.`country`, NEW.`latitude`, NEW.`longitude`, NEW.`geozone_id`, NEW.`odometer`);
UPDATE `bb_device` SET `current_journey` = (SELECT `id` FROM `bb_journey` WHERE `account_id` = NEW.`account_id` AND `device_id` = NEW.`device_id` ORDER BY `id` DESC LIMIT 1) WHERE `account_id` = NEW.`account_id` AND `device_id` = NEW.`device_id`;
END IF;
IF NEW.`status_code` = 62467 THEN
UPDATE `bb_journey` SET `end_timestamp` = NEW.`timestamp`, `end_street` = NEW.`street`, `end_city` = NEW.`city`, `end_state` = NEW.`state`, `end_country` = NEW.`country`, `end_latitude` = NEW.`latitude`, `end_longitude` = NEW.`longitude`, `end_geozone` = NEW.`geozone_id`, `end_odometer` = NEW.`odometer` WHERE `id` = (SELECT `current_journey` FROM `bb_device` WHERE `account_id` = NEW.`account_id` AND `device_id` = NEW.`device_id` ORDER BY `id` DESC LIMIT 1);
UPDATE `bb_device` SET `current_journey` = '' WHERE `account_id` = NEW.`account_id` AND `device_id` = NEW.`device_id`;
END IF;
END;
$$
我尝试在插入之前运行此触发器,这也没有用。当然,这必须是一个简单的解决方案:S。
提前致谢,
保罗