Is there a way to do it? Considering I have the following table:
id | value
----|------
1 | A
2 | B
If I try to insert the values (1, "C") I get Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY' as expected, considering id is a unique primary key. So, I tried using the following insert inside an AFTER INSERT ON trigger with the following insert syntax:
INSERT INTO table VALUES (NEW.id, NEW.value)
ON DUPLICATE KEY UPDATE NEW.id = NEW.id + 5000;
It removes the duplicate key error, but it just won't insert the duplicate one(s).
I made a procedure following Yogi's suggestion. This is what it looks like:
DELIMITER //
CREATE PROCEDURE set_keys(IN id INT, IN value char(1))
BEGIN
DECLARE CONTINUE HANDLER FOR 1062
SELECT concat('Duplicate keys detected: ',id,', ',value) AS msg;
INSERT INTO tests (id, value) VALUES(id + 5000, value);
END;
//
Is doing CALL set_keys(NEW.id, NEW.value); from now on the proper way to do it?
value.