By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,509 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

Trigger for creating csv of new data

P: 1
I'd like to create a trigger to export to csv the new data added to the table. I've written:

Expand|Select|Wrap|Line Numbers
  1. delimiter |
  2. create trigger trg_customer_csv after insert on customers
  3. for each row
  4. begin
  5. select new.account_code into outfile 'e:/trigfile.csv'
  6. fields terminated by ';'
  7. lines terminated by '\n' 
  8. from customers;
  9. end;
  10. |
this exports the new data once for every record in the table, so I got a csv with the new account_code 361 times.

I also really wanted to export all of the data, so have tried select new.* but nothing exported at all.

Any help would be appreciated.
Mar 1 '13 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,035
"I also really wanted to export all of the data, so have tried select new.* but nothing exported at all."
replace line 5 with:
Expand|Select|Wrap|Line Numbers
  1. select * into outfile 'e:/trigfile.csv'
This should export all the data in the table (providing the outputfile does not exist)

or, if you just want the complete last record:
Expand|Select|Wrap|Line Numbers
  1. select * 
  2. into outfile '/tmp/trigfile.csv'
  3. fields terminated by ';'
  4. lines terminated by '\n' 
  5. from customers
  6. where account_code=new.account_code;
  7. end;
Mar 3 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.