On Aug 25, 3:24 pm, Bhavesh Sharma <[email protected]> wrote:
> I have an issue where I am getting a large number of records from the
> database and I cant afford to keep it in the memory due to performance
> issues.
>
> Therefore using the following would be ideal,
>
> User.find_each(:batch_size => 5000, :start => 2000) do |user|
>   NewsLetter.weekly_deliver(user)
> end
>
> however,
>
> I would like to use find_by_sql since my query is user defined. Question
> is, is it possible to use find_by_sql with batch_size and iterate
> through all the record-sets?
>

With difficulty - you'd have to be able to modify the query passed to
find_by_sql in order to add the stuff that limits the number of
records returned (not that this isn't as simple as just adding limit/
offset - on mysql at least large offsets are slow. This might not be a
problem for you)

Fred

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to