I am trying to create a trigger that will update a GEOMETRY column based on lat/lng columns entered by the user. My trigger looks like so —
CREATE TRIGGER `tbl.foo`
AFTER INSERT ON `tbl` FOR EACH ROW
BEGIN
UPDATE tbl
SET coord = Point(lng, lat)
WHERE id = NEW.id;
END
However, I get the following error when I insert a new row with lng, lat values —
ERROR 1442 (HY000): Can’t update table ‘tbl’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Can I not create such a trigger? If not, what is the way to automate this?
Try to use BEFORE INSERT trigger and modify value you need, e.g. –
EDIT