My best effort so far is to use Model.connection.select_all supplying
the appropriate sql to get the data into a hash and then iterate through
the hash building a csv string by appending each hash item onto a result
string with << This is still taking over 15 seconds.
Well.. you can use the old approach of relying on your db when you need to deal with large amounts of data, since dbms are pretty good for that.
You could do like this
ActiveRecord::Base.connection.select_all("select concat(first_field , ',' , second_field,',',you_get_the_idea) as csv_row from your_table where you_tell_me")
So, that way you will get directly an array with a csv string on each row. You just need to put it to your file and that's it.
I don't know how fast it will be, but for sure better than before.