Reputation: 6639
I have tried several suggestions from stackoverflow, but I keep running into errors.
What I have is a table: test
I have 3 columns:
first (varchar)
last (varchar)
first_last (varchar)
What I want to do, is build a trigger, so when I enter first and last, and save it, the value of first_last is computed and saved. Here's what I have now:
Trigger name: update_first_last
Table: test
Time: AFTER
Event: INSERT
Definition: UPDATE test SET test.first_last=CONCAT(test.first, test.last)
The error I'm getting:
#1442 - Can't update table 'test' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Upvotes: 1
Views: 916
Reputation: 1376
Both the insert statement and your trigger want to modify the whole table which is not allowed. You can make something like this instead:
CREATE TRIGGER update_first_last
BEFORE INSERT
ON test
FOR EACH ROW
SET NEW.first_last=CONCAT(NEW.first, NEW.last)
If the columns first and last are not defined as NOT NULL then you should create a similar trigger for an UPDATE action.
Upvotes: 2