| Class | Sequel::Postgres::Dataset |
| In: |
lib/sequel/adapters/postgres.rb
|
| Parent: | Sequel::Dataset |
Dataset class for PostgreSQL datasets that use the pg, postgres, or postgres-pr driver.
| DatasetClass | = | self |
| APOS | = | Sequel::Dataset::APOS |
| PREPARED_ARG_PLACEHOLDER | = | LiteralString.new('$').freeze |
Execute the given type of statement with the hash of values.
# File lib/sequel/adapters/postgres.rb, line 708
708: def call(type, bind_vars={}, *values, &block)
709: ps = to_prepared_statement(type, values)
710: ps.extend(BindArgumentMethods)
711: ps.call(bind_vars, &block)
712: end
Yield all rows returned by executing the given SQL and converting the types.
# File lib/sequel/adapters/postgres.rb, line 596
596: def fetch_rows(sql)
597: return cursor_fetch_rows(sql){|h| yield h} if @opts[:cursor]
598: execute(sql){|res| yield_hash_rows(res, fetch_rows_set_cols(res)){|h| yield h}}
599: end
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
716: def prepare(type, name=nil, *values)
717: ps = to_prepared_statement(type, values)
718: ps.extend(PreparedStatementMethods)
719: if name
720: ps.prepared_statement_name = name
721: db.set_prepared_statement(name, ps)
722: end
723: ps
724: end
PostgreSQL uses $N for placeholders instead of ?, so use a $ as the placeholder.
# File lib/sequel/adapters/postgres.rb, line 730
730: def prepared_arg_placeholder
731: PREPARED_ARG_PLACEHOLDER
732: end
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:
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
616: def use_cursor(opts={})
617: clone(:cursor=>{:rows_per_fetch=>1000}.merge(opts))
618: end