Updating of NEW row is not allowed in after trigger
Asked Answered
P

1

5

Why do I get an error using this trigger?

CREATE TRIGGER save_Assignee AFTER INSERT ON changeitem
FOR EACH ROW 
BEGIN 
    SET new.assignee = (
        SELECT assignee
        FROM jiraissue INNER JOIN changegroup ON jiraissue.ID = changegroup.issueid
    )
END


Error message:

#1362 - Updating of NEW row is not allowed in after trigger

Pettiford answered 17/9, 2015 at 11:20 Comment(0)
B
14

That is correct. You need a before insert trigger if you want to modify the data:

create TRIGGER save_Assignee BEFORE INSERT ON changeitem FOR EACH ROW
BEGIN
    SET new.assignee = (select assignee
                        from jiraissue INNER JOIN
                             changegroup
                             ON jiraissue.ID = changegroup.issueid
                       )
END

As suggested by the name, the AFTER insert trigger is run after the data has been updated. So, if you want to update the same row, use a before trigger.

Your subquery looks suspicious because it is not correlated with new and it looks like it could return more than one row.

Badger answered 17/9, 2015 at 11:30 Comment(1)
same as: #17823957Angi

© 2022 - 2024 — McMap. All rights reserved.