ActiveRecord and Cursors (with PostgreSQL)



Is there a way to access database cursors using Rails, preferably
through ActiveRecord? I believe the standard usage loads the entire
result set into memory. However, for extremely large results (or when I
don’t want to abuse memory levels), this is sometimes not possible.

While it may not be feasible for a web application to process huge
amounts of data, I want to run this as an asynchronous task, “cron” task
or similar.

I recently encountered this problem with my Perl application returning a
large result set from PostgreSQL. The solution was to execute ‘define
cursor’ and ‘fetch 1000’ commands, with the fetch methods. I hope to
port this application or feature to Ruby on Rails.