I need to set up a trigger in MariaDB 10.1 which inserts rows in another table. So far the trigger looks like this for a single record:
DELIMITER //
CREATE TRIGGER generate_items
AFTER INSERT
ON my_table
FOR EACH ROW
BEGIN
-- some_id is the id from my_table
INSERT INTO another_table(some_id, some_value)
VALUES (NEW.id, 'x');
END;
//
DELIMITER ;
My problem is that some_value
is not the only record to be inserted but a list of values fetched from another table. Actually I would need something like this in the trigger:
-- Pseudo-code for illustrating
SET @values = SELECT value FROM some_table WHERE condition = true;
FOREACH(@value in @values) DO
INSERT INTO another_table(some_id, some_value) VALUES (NEW.id, @value);
END
Which possibilities would I have with MariaDB 10.1? I read that MariaDB 10.3 offers a FOR-loop but we cannot upgrade the database yet.