# ActiveRecord and Cursors (with PostgreSQL)

**URL:** <https://www.ruby-forum.com/t/activerecord-and-cursors-with-postgresql/51999>\
**Category:** Rails\
**Created:** [January 10, 2006, 12:05am UTC](https://www.ruby-forum.com/t/activerecord-and-cursors-with-postgresql/51999 "2006-01-10T00:05:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![allen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@allen](https://www.ruby-forum.com/u/allen)\
**Post date:** [January 10, 2006, 12:05am UTC](https://www.ruby-forum.com/t/activerecord-and-cursors-with-postgresql/51999/1 "2006-01-10T00:05:03Z")

</div>

Hi,

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.

Thanks,  
Allen
