Back (Current repo: scraps)

random scraps and notes that are useful to me
To clone this repository:
git clone https://git.viktor1993.net/scraps.git
Log | Download | Files | Refs

trim_table_from_old_data.sql (473B)


-- add to crontab so that it can clean up from time to time
DROP procedure IF EXISTS `sp_super_delete_table_x`;

DELIMITER $$

CREATE PROCEDURE `sp_super_delete_table_x`()
MODIFIES SQL DATA
BEGIN

REPEAT
    DO sleep(2);
        DELETE FROM `some_schema`.`x`
        WHERE date_entered < DATE_SUB(CURRENT_DATE(), INTERVAL 3 month)
        ORDER BY date_entered
        LIMIT 20000; -- or whatever makes sense
        UNTIL row_count() = 0
END REPEAT;


END $$

DELIMITER ;