Why don't you output the data from the database directly into CSV, which is one of the output option of the database plugin?
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫