Class/Module Index [+]

Quicksearch

Sequel::Postgres::Dataset

Dataset class for PostgreSQL datasets that use the pg, postgres, or postgres-pr driver.

Public Instance Methods

call(type, bind_vars={}, *values, &block) click to toggle source

Execute the given type of statement with the hash of values.

# File lib/sequel/adapters/postgres.rb, line 708
def call(type, bind_vars={}, *values, &block)
  ps = to_prepared_statement(type, values)
  ps.extend(BindArgumentMethods)
  ps.call(bind_vars, &block)
end
fetch_rows(sql) click to toggle source

Yield all rows returned by executing the given SQL and converting the types.

# File lib/sequel/adapters/postgres.rb, line 596
def fetch_rows(sql)
  return cursor_fetch_rows(sql){|h| yield h} if @opts[:cursor]
  execute(sql){|res| yield_hash_rows(res, fetch_rows_set_cols(res)){|h| yield h}}
end
prepare(type, name=nil, *values) click to toggle source

Prepare the given type of statement with the given name, and store it in the database to be called later.

# File lib/sequel/adapters/postgres.rb, line 716
def prepare(type, name=nil, *values)
  ps = to_prepared_statement(type, values)
  ps.extend(PreparedStatementMethods)
  if name
    ps.prepared_statement_name = name
    db.set_prepared_statement(name, ps)
  end
  ps
end
prepared_arg_placeholder() click to toggle source

PostgreSQL uses $N for placeholders instead of ?, so use a $ as the placeholder.

# File lib/sequel/adapters/postgres.rb, line 730
def prepared_arg_placeholder
  PREPARED_ARG_PLACEHOLDER
end
use_cursor(opts={}) click to toggle source

Uses a cursor for fetching records, instead of fetching the entire result set at once. Can be used to process large datasets without holding all rows in memory (which is what the underlying drivers do by default). Options:

  • :rows_per_fetch - the number of rows per fetch (default 1000). Higher numbers result in fewer queries but greater memory use.

Usage:

DB[:huge_table].use_cursor.each{|row| p row}
DB[:huge_table].use_cursor(:rows_per_fetch=>10000).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 616
def use_cursor(opts={})
  clone(:cursor=>{:rows_per_fetch=>1000}.merge(opts))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.