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.

### Methods

call fetch_rows prepare prepared_arg_placeholder

### Included Modules

Sequel::Postgres::DatasetMethods

### Classes and Modules

Module Sequel::Postgres::Dataset::ArgumentMapper
Module Sequel::Postgres::Dataset::BindArgumentMethods
Module Sequel::Postgres::Dataset::PreparedStatementMethods

### Constants

PREPARED_ARG_PLACEHOLDER | = | LiteralString.new('$').freeze

### Public Instance methods

call(type, hash, values=nil, &block)

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

[Source]

         # File lib/sequel/adapters/postgres.rb, line 414
    414:         def call(type, hash, values=nil, &block)
    415:           ps = to_prepared_statement(type, values)
    416:           ps.extend(BindArgumentMethods)
    417:           ps.call(hash, &block)
    418:         end

fetch_rows(sql) {|converted_rec| ...}

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

[Source]

         # File lib/sequel/adapters/postgres.rb, line 311
    311:       def fetch_rows(sql)
    312:         cols = []
    313:         execute(sql) do |res|
    314:           res.nfields.times do |fieldnum|
    315:             cols << [fieldnum, PG_TYPES[res.ftype(fieldnum)], output_identifier(res.fname(fieldnum))]
    316:           end
    317:           @columns = cols.map{|c| c.at(2)}
    318:           res.ntuples.times do |recnum|
    319:             converted_rec = {}
    320:             cols.each do |fieldnum, type_proc, fieldsym|
    321:               value = res.getvalue(recnum, fieldnum)
    322:               converted_rec[fieldsym] = (value && type_proc) ? type_proc.call(value) : value
    323:             end
    324:             yield converted_rec
    325:           end
    326:         end
    327:       end

prepare(type, name=nil, values=nil)

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

[Source]

         # File lib/sequel/adapters/postgres.rb, line 422
    422:         def prepare(type, name=nil, values=nil)
    423:           ps = to_prepared_statement(type, values)
    424:           ps.extend(PreparedStatementMethods)
    425:           if name
    426:             ps.prepared_statement_name = name
    427:             db.prepared_statements[name] = ps
    428:           end
    429:           ps
    430:         end

prepared_arg_placeholder()

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

[Source]

         # File lib/sequel/adapters/postgres.rb, line 436
    436:         def prepared_arg_placeholder
    437:           PREPARED_ARG_PLACEHOLDER
    438:         end

[Validate]