I’m interested in creating a trigger that will write a file after I import a csv into my table. The file name includes a time stamp and my code isn’t working properly. Here’s what I have so far.
DELIMITER $$
CREATE TRIGGER peachtree_trigger
AFTER INSERT ON peachtree
FOR EACH ROW
BEGIN
SET @sql_text = CONCAT("SELECT * FROM peachtree
INTO OUTFILE '/srv/samba/share/peachtree_",
DATE_FORMAT(NOW(), '%Y_%m_%D'), ".csv'");
PREPARE s1 FROM @sql_text;
EXECUTE s1;
DROP PREPARE s1;
END $$ DELIMITER ;
The set statement works fine outside of the trigger. However when I execute the above set of code and then try SHOW TRIGGERS IN test; it returns an empty set. If anyone could help I would be very grateful.
from http://dev.mysql.com/doc/refman/5.5/en/stored-program-restrictions.html
<snip>
SQL prepared statements (PREPARE, EXECUTE, DEALLOCATE PREPARE) can be used in stored procedures, but not stored functions or triggers. Thus, stored functions and triggers cannot use dynamic SQL (where you construct statements as strings and then execute them).
</snip>