I want to create an event that every 15 days executes a procedure. This procedure must to create a new partition. I am doing the following:
/*Vars
v_tab --> logic tables's name
v_year --> year... to use it as part of name
v_fech --> this is used to get the current date plus 15 days
v_day --> this is the numbers of days to add to the current date
*/
DROP PROCEDURE IF EXISTS CreatePartition;
delimiter //
CREATE PROCEDURE CreatePartition (IN v_day INT)
BEGIN
DECLARE v_year INT;
DECLARE v_fech DATE;
DECLARE v_tab VARCHAR(20);
SET v_year = (select curdate()+0);
SET v_fech = (DATE_ADD(CURDATE(), INTERVAL v_day DAY));
SET v_tab = (select concat('p',v_year)); <--- the char p is because it doesn't accept name with only numbers
ALTER TABLE SystemEvents PARTITION BY RANGE(TO_DAYS(DeviceReportedTime))(
PARTITION v_tab VALUES LESS THAN (TO_DAYS("v_fech")),
PARTITION pDefault VALUES LESS THAN MAXVALUE
);
END
//
delimiter ;
If I exec this procedure it works, but if I exec it inside an event, it doesn't work
call CreatePartition(15);
The following doesn't work and I don't know why
CREATE EVENT EventPruebas
ON SCHEDULE
EVERY 15 DAY
DO
call CreatePartition(15);
and I get this error...
ERROR 1064 (42000): Not allowed to use NULL value in VALUES LESS THAN near '),
PARTITION p230101 VALUES LESS THAN MAXVALUE