致力于mysql.5.7
这是我的bugs
桌子
MySQL [jira_statistics]> describe bugs;
+---------------------------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------------------------+--------------+------+-----+---------+-------+
| issue_key | varchar(45) | NO | PRI | NULL | |
| release_name | varchar(45) | YES | MUL | NULL | |
| issue_summary | varchar(200) | YES | | NULL | |
| story_points | int(11) | NO | | 0 | |
| qa_reopened | float | NO | | 0 | |
| done_reopened | float | NO | | 0 | |
此表通过定期调用LOAD DATA LOCAL INFILE bugs <file.csv>
无论何时进行此更新(它可能会更新现有行和/或插入新行),我都希望通过以下触发器来更新具有某些产生的统计信息的另一个表
create trigger update_bugs_stats after insert on `jira_statistics`.`bugs` for each row
begin
delimiter ;
-- STORY POINTS -------------------------
SELECT AVG(story_points) INTO @avg_bugs_storypoints FROM `jira_statistics`.`bugs` WHERE release_name = new.release_name;
SELECT MAX(story_points) INTO @max_bugs_storypoints FROM `jira_statistics`.`bugs` WHERE release_name = new.release_name;
SELECT MIN(story_points) INTO @min_bugs_storypoints FROM `jira_statistics`.`bugs` WHERE release_name = new.release_name;
INSERT INTO storypoints_stats (release_name, avg_bugs_storypoints, max_bugs_storypoints, min_bugs_storypoints)
VALUES (relName, @avg_bugs_storypoints, @max_bugs_storypoints, @min_bugs_storypoints)
ON DUPLICATE KEY UPDATE
relName=new.release_name,
avg_bugs_storypoints=@avg_bugs_storypoints,
max_bugs_storypoints=@max_bugs_storypoints,
min_bugs_storypoints=@min_bugs_storypoints;
但是,每当尝试创建触发器时,都会给我以下错误:
new.release_name
子句中的未知列where
。
为什么无法识别new
关键字?
答案 0 :(得分:0)
因为new被保留为系统字
参考:https://dev.mysql.com/doc/refman/8.0/en/keywords.html
请修改
new.release_name ==> `new`.`release_name`
等等。
答案 1 :(得分:0)
错误比我想象的还要愚蠢;
我直接在sql查询编辑器上工作,而不是在mysql工作台的“触发器”选项卡上工作,因此它无法正确解析new
关键字`。