Select into outfile, and then delete the selected rows
I've just put together a really simple stored-procedure that will run every couple of minutes which creates an outfile:
From this we're generating a filename with a datetime stamp in the filename as required by the system that is reading it and it only reads in lines that are scheduled to be read (there is a 15 minute delay that is put on every entry via the `scheduled` field.)
SET @sql_text = CONCAT ("SELECT `out_line` into outfile 'wms-in."
, DATE_FORMAT( NOW(), '%Y%m%d%H%i%s')
, "' LINES TERMINATED BY '\n'"
, " FROM jobs_out WHERE `scheduled` < now();");
PREPARE s1 FROM @sql_text;
DROP PREPARE s1;
This all works perfect, just as we need it to, but the problem that I now have is that the row stays there forever. I need to remove it once it's been read in to the file. How best to do this?