Method: Sequel::Postgres::Dataset#use_cursor

Defined in:

#use_cursor(opts = OPTS) ⇒ Object

Uses a cursor for fetching records, instead of fetching the entire result set at once. Note this uses a transaction around the cursor usage by default and can be changed using `hold: true` as described below. Cursors can be used to process large datasets without holding all rows in memory (which is what the underlying drivers may do by default). Options:


The name assigned to the cursor (default 'sequel_cursor'). Nested cursors require different names.


Declare the cursor WITH HOLD and don't use transaction around the cursor usage.


The number of rows per fetch (default 1000). Higher numbers result in fewer queries but greater memory use.


DB[:huge_table].use_cursor.each{|row| p row}
DB[:huge_table].use_cursor(rows_per_fetch: 10000).each{|row| p row}
DB[:huge_table].use_cursor(cursor_name: 'my_cursor').each{|row| p row}

This is untested with the prepared statement/bound variable support, and unlikely to work with either.

# File 'lib/sequel/adapters/postgres.rb', line 643

def use_cursor(opts=OPTS)