Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create MySQL event with a dynamic event name

I have to write a stored procedure in which a event needs to be created. Since the stored procedure call depends on the action triggered, a different name needs to be given to the event created.

CREATE EVENT variable
    ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE
    DO
    Insert into dummy ('abc');

The variable name needs to be a dynamic variable, however mysql doesnt let me do that from a stored procedure. How can this be achieved?

like image 297
Maxim Dsouza Avatar asked Dec 19 '25 21:12

Maxim Dsouza


1 Answers

It's not possible in MySQL, this:

PREPARE stmt_name FROM CONCAT(CREATE EVENT ",@variable
    ,"ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE "
    ,"DO Insert into dummy (test) VALUES (?);"

SET @test_parm = "abc";

EXECUTE stmt_name USING @test_parm;
DEALLOCATE PREPARE stmt_name;

Doesn't work because you cannot do that in a prepared statement.

See: http://dev.mysql.com/doc/refman/5.5/en/sql-syntax-prepared-statements.html

like image 85
Johan Avatar answered Dec 22 '25 13:12

Johan