Module: Sequel::Postgres::DatasetMethods

### Home Classes Methods

### In Files

- lib/sequel/adapters/shared/postgres.rb

### Namespace

- MODULE Sequel::Postgres::DatasetMethods::PreparedStatementMethods

### Methods

- ::extended
- ::included
- #analyze
- #disable_insert_returning
- #explain
- #for_share
- #full_text_search
- #insert
- #insert_returning_sql
- #insert_select
- #lock
- #multi_insert_sql
- #supports_distinct_on?
- #supports_modifying_joins?
- #supports_timestamp_timezones?
- #supports_window_functions?
- #window

### Files

- CHANGELOG
- COPYING
- README.rdoc
- advanced_associations.rdoc
- association_basics.rdoc
- cheat_sheet.rdoc
- dataset_basics.rdoc
- dataset_filtering.rdoc
- migration.rdoc
- model_hooks.rdoc
- opening_databases.rdoc
- prepared_statements.rdoc
- querying.rdoc
- reflection.rdoc
- 1.0.txt
- 1.1.txt
- 1.3.txt
- 1.4.0.txt
- 1.5.0.txt
- 2.0.0.txt
- 2.1.0.txt
- 2.10.0.txt
- 2.11.0.txt
- 2.12.0.txt
- 2.2.0.txt
- 2.3.0.txt
- 2.4.0.txt
- 2.5.0.txt
- 2.6.0.txt
- 2.7.0.txt
- 2.8.0.txt
- 2.9.0.txt
- 3.0.0.txt
- 3.1.0.txt
- 3.10.0.txt
- 3.11.0.txt
- 3.12.0.txt
- 3.2.0.txt
- 3.3.0.txt
- 3.4.0.txt
- 3.5.0.txt
- 3.6.0.txt
- 3.7.0.txt
- 3.8.0.txt
- 3.9.0.txt
- sharding.rdoc
- sql.rdoc
- virtual_rows.rdoc

### Class/Module Index

Quicksearch

- Sequel
- Sequel::ADO
- Sequel::ADO::Database
- Sequel::ADO::Dataset
- Sequel::ADO::MSSQL
- Sequel::ADO::MSSQL::DatabaseMethods
- Sequel::ADO::MSSQL::Dataset
- Sequel::AdapterNotFound
- Sequel::Amalgalite
- Sequel::Amalgalite::Database
- Sequel::Amalgalite::Dataset
- Sequel::Amalgalite::SequelTypeMap
- Sequel::BasicObject
- Sequel::BeforeHookFailed
- Sequel::ConnectionPool
- Sequel::ConnectionPool::ClassMethods
- Sequel::DB2
- Sequel::DB2::Database
- Sequel::DB2::Dataset
- Sequel::DBI
- Sequel::DBI::Database
- Sequel::DBI::Dataset
- Sequel::DataObjects
- Sequel::DataObjects::Database
- Sequel::DataObjects::Dataset
- Sequel::DataObjects::MySQL
- Sequel::DataObjects::MySQL::DatabaseMethods
- Sequel::DataObjects::MySQL::Dataset
- Sequel::DataObjects::Postgres
- Sequel::DataObjects::Postgres::AdapterMethods
- Sequel::DataObjects::Postgres::DatabaseMethods
- Sequel::DataObjects::Postgres::Dataset
- Sequel::DataObjects::SQLite
- Sequel::DataObjects::SQLite::DatabaseMethods
- Sequel::DataObjects::SQLite::Dataset
- Sequel::Database
- Sequel::DatabaseConnectionError
- Sequel::DatabaseDisconnectError
- Sequel::DatabaseError
- Sequel::Dataset
- Sequel::Dataset::ArgumentMapper
- Sequel::Dataset::Pagination
- Sequel::Dataset::PreparedStatementMethods
- Sequel::Dataset::QueryBlockCopy
- Sequel::Dataset::StoredProcedureMethods
- Sequel::Dataset::StoredProcedures
- Sequel::Dataset::UnnumberedArgumentMapper
- Sequel::Error
- Sequel::Error::AdapterNotFound
- Sequel::Error::InvalidOperation
- Sequel::Error::InvalidValue
- Sequel::Error::PoolTimeoutError
- Sequel::Error::Rollback
- Sequel::Firebird
- Sequel::Firebird::Database
- Sequel::Firebird::Dataset
- Sequel::Inflections
- Sequel::Informix
- Sequel::Informix::Database
- Sequel::Informix::Dataset
- Sequel::IntegerMigrator
- Sequel::InvalidOperation
- Sequel::InvalidValue
- Sequel::JDBC
- Sequel::JDBC::AS400
- Sequel::JDBC::AS400::DatabaseMethods
- Sequel::JDBC::AS400::Dataset
- Sequel::JDBC::Database
- Sequel::JDBC::Dataset
- Sequel::JDBC::Dataset::PreparedStatementMethods
- Sequel::JDBC::Dataset::StoredProcedureMethods
- Sequel::JDBC::H2
- Sequel::JDBC::H2::DatabaseMethods
- Sequel::JDBC::H2::Dataset
- Sequel::JDBC::JavaLang
- Sequel::JDBC::JavaSQL
- Sequel::JDBC::JavaxNaming
- Sequel::JDBC::MSSQL
- Sequel::JDBC::MSSQL::DatabaseMethods
- Sequel::JDBC::MSSQL::Dataset
- Sequel::JDBC::MySQL
- Sequel::JDBC::MySQL::DatabaseMethods
- Sequel::JDBC::MySQL::Dataset
- Sequel::JDBC::Oracle
- Sequel::JDBC::Oracle::DatabaseMethods
- Sequel::JDBC::Oracle::Dataset
- Sequel::JDBC::Postgres
- Sequel::JDBC::Postgres::AdapterMethods
- Sequel::JDBC::Postgres::DatabaseMethods
- Sequel::JDBC::Postgres::Dataset
- Sequel::JDBC::SQLite
- Sequel::JDBC::SQLite::DatabaseMethods
- Sequel::JDBC::SQLite::Dataset
- Sequel::LiteralString
- Sequel::LooserTypecasting
- Sequel::MSSQL
- Sequel::MSSQL::DatabaseMethods
- Sequel::MSSQL::DatasetMethods
- Sequel::Metaprogramming
- Sequel::Migration
- Sequel::MigrationDSL
- Sequel::Migrator
- Sequel::Migrator::Error
- Sequel::Model
- Sequel::Model::Associations
- Sequel::Model::Associations::AssociationDatasetMethods
- Sequel::Model::Associations::AssociationReflection
- Sequel::Model::Associations::ClassMethods
- Sequel::Model::Associations::DatasetMethods
- Sequel::Model::Associations::InstanceMethods
- Sequel::Model::Associations::ManyToManyAssociationReflection
- Sequel::Model::Associations::ManyToOneAssociationReflection
- Sequel::Model::Associations::OneToManyAssociationReflection
- Sequel::Model::Associations::OneToOneAssociationReflection
- Sequel::Model::ClassMethods
- Sequel::Model::DatasetMethods
- Sequel::Model::Errors
- Sequel::Model::InstanceMethods
- Sequel::MySQL
- Sequel::MySQL::Database
- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::Dataset
- Sequel::MySQL::Dataset::CallableStatementMethods
- Sequel::MySQL::Dataset::PreparedStatementMethods
- Sequel::MySQL::Dataset::StoredProcedureMethods
- Sequel::MySQL::DatasetMethods
- Sequel::NamedTimezones
- Sequel::NoExistingObject
- Sequel::NotImplemented
- Sequel::ODBC
- Sequel::ODBC::Database
- Sequel::ODBC::Dataset
- Sequel::ODBC::MSSQL
- Sequel::ODBC::MSSQL::DatabaseMethods
- Sequel::ODBC::MSSQL::Dataset
- Sequel::OpenBase
- Sequel::OpenBase::Database
- Sequel::OpenBase::Dataset
- Sequel::Oracle
- Sequel::Oracle::Database
- Sequel::Oracle::DatabaseMethods
- Sequel::Oracle::Dataset
- Sequel::Oracle::DatasetMethods
- Sequel::Plugins
- Sequel::Plugins::ActiveModel
- Sequel::Plugins::ActiveModel::InstanceMethods
- Sequel::Plugins::AssociationDependencies
- Sequel::Plugins::AssociationDependencies::ClassMethods
- Sequel::Plugins::AssociationDependencies::InstanceMethods
- Sequel::Plugins::AssociationPks
- Sequel::Plugins::AssociationPks::ClassMethods
- Sequel::Plugins::AssociationProxies
- Sequel::Plugins::AssociationProxies::AssociationProxy
- Sequel::Plugins::AssociationProxies::ClassMethods
- Sequel::Plugins::BooleanReaders
- Sequel::Plugins::BooleanReaders::ClassMethods
- Sequel::Plugins::Caching
- Sequel::Plugins::Caching::ClassMethods
- Sequel::Plugins::Caching::InstanceMethods
- Sequel::Plugins::ClassTableInheritance
- Sequel::Plugins::ClassTableInheritance::ClassMethods
- Sequel::Plugins::ClassTableInheritance::InstanceMethods
- Sequel::Plugins::Composition
- Sequel::Plugins::Composition::ClassMethods
- Sequel::Plugins::Composition::InstanceMethods
- Sequel::Plugins::ForceEncoding
- Sequel::Plugins::ForceEncoding::ClassMethods
- Sequel::Plugins::ForceEncoding::InstanceMethods
- Sequel::Plugins::HookClassMethods
- Sequel::Plugins::HookClassMethods::ClassMethods
- Sequel::Plugins::HookClassMethods::InstanceMethods
- Sequel::Plugins::IdentityMap
- Sequel::Plugins::IdentityMap::ClassMethods
- Sequel::Plugins::IdentityMap::InstanceMethods
- Sequel::Plugins::InstanceFilters
- Sequel::Plugins::InstanceFilters::InstanceMethods
- Sequel::Plugins::InstanceHooks
- Sequel::Plugins::InstanceHooks::InstanceMethods
- Sequel::Plugins::LazyAttributes
- Sequel::Plugins::LazyAttributes::ClassMethods
- Sequel::Plugins::LazyAttributes::InstanceMethods
- Sequel::Plugins::ManyThroughMany
- Sequel::Plugins::ManyThroughMany::ClassMethods
- Sequel::Plugins::ManyThroughMany::ManyThroughManyAssociationReflection
- Sequel::Plugins::NestedAttributes
- Sequel::Plugins::NestedAttributes::ClassMethods
- Sequel::Plugins::NestedAttributes::InstanceMethods
- Sequel::Plugins::OptimisticLocking
- Sequel::Plugins::OptimisticLocking::ClassMethods
- Sequel::Plugins::OptimisticLocking::InstanceMethods
- Sequel::Plugins::RcteTree
- Sequel::Plugins::Schema
- Sequel::Plugins::Schema::ClassMethods
- Sequel::Plugins::Serialization
- Sequel::Plugins::Serialization::ClassMethods
- Sequel::Plugins::Serialization::InstanceMethods
- Sequel::Plugins::Sharding
- Sequel::Plugins::Sharding::ClassMethods
- Sequel::Plugins::Sharding::DatasetMethods
- Sequel::Plugins::Sharding::InstanceMethods
- Sequel::Plugins::SingleTableInheritance
- Sequel::Plugins::SingleTableInheritance::ClassMethods
- Sequel::Plugins::SingleTableInheritance::InstanceMethods
- Sequel::Plugins::SkipCreateRefresh
- Sequel::Plugins::SkipCreateRefresh::InstanceMethods
- Sequel::Plugins::StringStripper
- Sequel::Plugins::StringStripper::InstanceMethods
- Sequel::Plugins::Subclasses
- Sequel::Plugins::Subclasses::ClassMethods
- Sequel::Plugins::TacticalEagerLoading
- Sequel::Plugins::TacticalEagerLoading::DatasetMethods
- Sequel::Plugins::TacticalEagerLoading::InstanceMethods
- Sequel::Plugins::Timestamps
- Sequel::Plugins::Timestamps::ClassMethods
- Sequel::Plugins::Timestamps::InstanceMethods
- Sequel::Plugins::Touch
- Sequel::Plugins::Touch::ClassMethods
- Sequel::Plugins::Touch::InstanceMethods
- Sequel::Plugins::TypecastOnLoad
- Sequel::Plugins::TypecastOnLoad::ClassMethods
- Sequel::Plugins::TypecastOnLoad::InstanceMethods
- Sequel::Plugins::UpdatePrimaryKey
- Sequel::Plugins::UpdatePrimaryKey::ClassMethods
- Sequel::Plugins::UpdatePrimaryKey::InstanceMethods
- Sequel::Plugins::ValidationClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods::Generator
- Sequel::Plugins::ValidationClassMethods::InstanceMethods
- Sequel::Plugins::ValidationHelpers
- Sequel::Plugins::ValidationHelpers::InstanceMethods
- Sequel::PoolTimeout
- Sequel::Postgres
- Sequel::Postgres::Adapter
- Sequel::Postgres::AdapterMethods
- Sequel::Postgres::Database
- Sequel::Postgres::DatabaseMethods
- Sequel::Postgres::Dataset
- Sequel::Postgres::Dataset::ArgumentMapper
- Sequel::Postgres::Dataset::BindArgumentMethods
- Sequel::Postgres::Dataset::PreparedStatementMethods
- Sequel::Postgres::DatasetMethods
- Sequel::Postgres::DatasetMethods::PreparedStatementMethods
- Sequel::PrettyTable
- Sequel::Progress
- Sequel::Progress::DatabaseMethods
- Sequel::Progress::DatasetMethods
- Sequel::Rollback
- Sequel::SQL
- Sequel::SQL::AliasMethods
- Sequel::SQL::AliasedExpression
- Sequel::SQL::BitwiseMethods
- Sequel::SQL::Blob
- Sequel::SQL::BooleanConstant
- Sequel::SQL::BooleanExpression
- Sequel::SQL::BooleanMethods
- Sequel::SQL::CaseExpression
- Sequel::SQL::Cast
- Sequel::SQL::CastMethods
- Sequel::SQL::ColumnAll
- Sequel::SQL::ComplexExpression
- Sequel::SQL::ComplexExpressionMethods
- Sequel::SQL::Constant
- Sequel::SQL::Constants
- Sequel::SQL::Expression
- Sequel::SQL::Function
- Sequel::SQL::GenericComplexExpression
- Sequel::SQL::GenericExpression
- Sequel::SQL::Identifier
- Sequel::SQL::IdentifierMethods
- Sequel::SQL::InequalityMethods
- Sequel::SQL::JoinClause
- Sequel::SQL::JoinOnClause
- Sequel::SQL::JoinUsingClause
- Sequel::SQL::NegativeBooleanConstant
- Sequel::SQL::NoBooleanInputMethods
- Sequel::SQL::NumericExpression
- Sequel::SQL::NumericMethods
- Sequel::SQL::OrderMethods
- Sequel::SQL::OrderedExpression
- Sequel::SQL::PlaceholderLiteralString
- Sequel::SQL::QualifiedIdentifier
- Sequel::SQL::QualifyingMethods
- Sequel::SQL::SQLArray
- Sequel::SQL::StringConcatenationMethods
- Sequel::SQL::StringExpression
- Sequel::SQL::StringMethods
- Sequel::SQL::Subscript
- Sequel::SQL::SubscriptMethods
- Sequel::SQL::VirtualRow
- Sequel::SQL::Window
- Sequel::SQL::WindowFunction
- Sequel::SQLite
- Sequel::SQLite::Database
- Sequel::SQLite::DatabaseMethods
- Sequel::SQLite::Dataset
- Sequel::SQLite::Dataset::ArgumentMapper
- Sequel::SQLite::Dataset::PreparedStatementMethods
- Sequel::SQLite::DatasetMethods
- Sequel::Schema
- Sequel::Schema::AlterTableGenerator
- Sequel::Schema::Generator
- Sequel::ShardedSingleConnectionPool
- Sequel::ShardedThreadedConnectionPool
- Sequel::SimpleMigration
- Sequel::SingleConnectionPool
- Sequel::ThreadLocalTimezones
- Sequel::ThreadedConnectionPool
- Sequel::TimestampMigrator
- Sequel::Timezones
- Sequel::ValidationFailed
- String
- String::Inflections
- Array
- FalseClass
- Hash
- NilClass
- Numeric
- Object
- PGconn
- PGresult
- Proc
- Symbol
- TrueClass

No matching classes.

# Sequel::Postgres::DatasetMethods

Instance methods for datasets that connect to a PostgreSQL database.

### Constants

ACCESS_EXCLUSIVE
ACCESS_SHARE
BOOL_FALSE
BOOL_TRUE
COMMA_SEPARATOR
DELETE_CLAUSE_METHODS
EXCLUSIVE
EXPLAIN
EXPLAIN_ANALYZE
FOR_SHARE
LOCK
NULL
PG_TIMESTAMP_FORMAT
QUERY_PLAN
ROW_EXCLUSIVE
ROW_SHARE
SELECT_CLAUSE_METHODS
SELECT_CLAUSE_METHODS_84
SHARE
SHARE_ROW_EXCLUSIVE
SHARE_UPDATE_EXCLUSIVE
SQL_WITH_RECURSIVE
UPDATE_CLAUSE_METHODS

### Public Class Methods

extended(obj) click to toggle source

Add the disable_insert_returning! mutation method

    # File lib/sequel/adapters/shared/postgres.rb, line 616
    def self.extended(obj)
      obj.def_mutation_method(:disable_insert_returning)
    end

included(mod) click to toggle source

Add the disable_insert_returning! mutation method

    # File lib/sequel/adapters/shared/postgres.rb, line 621
    def self.included(mod)
      mod.def_mutation_method(:disable_insert_returning)
    end

### Public Instance Methods

analyze() click to toggle source

Return the results of an ANALYZE query as a string

    # File lib/sequel/adapters/shared/postgres.rb, line 626
    def analyze
      explain(:analyze=>true)
    end

disable_insert_returning() click to toggle source

Disable the use of INSERT RETURNING, even if the server supports it

    # File lib/sequel/adapters/shared/postgres.rb, line 631
    def disable_insert_returning
      clone(:disable_insert_returning=>true)
    end

explain(opts={}) click to toggle source

Return the results of an EXPLAIN query as a string

    # File lib/sequel/adapters/shared/postgres.rb, line 636
    def explain(opts={})
      with_sql((opts[:analyze] ? EXPLAIN_ANALYZE : EXPLAIN) + select_sql).map(QUERY_PLAN).join("\r\n")
    end

for_share() click to toggle source

Return a cloned dataset which will use FOR SHARE to lock returned rows.

    # File lib/sequel/adapters/shared/postgres.rb, line 641
    def for_share
      lock_style(:share)
    end

full_text_search(cols, terms, opts = {}) click to toggle source

PostgreSQL specific full text search syntax, using tsearch2 (included in 8.3 by default, and available for earlier versions as an add-on).

    # File lib/sequel/adapters/shared/postgres.rb, line 647
    def full_text_search(cols, terms, opts = {})
      lang = opts[:language] || 'simple'
      filter("to_tsvector(#{literal(lang)}, #{full_text_string_join(cols)}) @@ to_tsquery(#{literal(lang)}, #{literal(Array(terms).join(' | '))})")
    end

insert(*values) click to toggle source

Insert given values into the database.

    # File lib/sequel/adapters/shared/postgres.rb, line 653
    def insert(*values)
      if @opts[:sql]
        execute_insert(insert_sql(*values))
      elsif @opts[:disable_insert_returning] || server_version < 80200
        execute_insert(insert_sql(*values), :table=>opts[:from].first, :values=>values.size == 1 ? values.first : values)
      else
        clone(default_server_opts(:sql=>insert_returning_pk_sql(*values))).single_value
      end
    end

insert_returning_sql(returning, *values) click to toggle source

Use the RETURNING clause to return the columns listed in returning.

    # File lib/sequel/adapters/shared/postgres.rb, line 664
    def insert_returning_sql(returning, *values)
      "#{insert_sql(*values)} RETURNING #{column_list(Array(returning))}"
    end

insert_select(*values) click to toggle source

Insert a record returning the record inserted

    # File lib/sequel/adapters/shared/postgres.rb, line 669
    def insert_select(*values)
      return if opts[:disable_insert_returning] || server_version < 80200
      naked.clone(default_server_opts(:sql=>insert_returning_sql(nil, *values))).single_record
    end

lock(mode, opts={}) click to toggle source

Locks all tables in the dataset’s FROM clause (but not in JOINs) with the specified mode (e.g. ‘EXCLUSIVE’). If a block is given, starts a new transaction, locks the table, and yields. If a block is not given just locks the tables. Note that PostgreSQL will probably raise an error if you lock the table outside of an existing transaction. Returns nil.

    # File lib/sequel/adapters/shared/postgres.rb, line 679
    def lock(mode, opts={})
      if block_given? # perform locking inside a transaction and yield to block
        @db.transaction(opts){lock(mode, opts); yield}
      else
        @db.execute(LOCK % [source_list(@opts[:from]), mode], opts) # lock without a transaction
      end
      nil
    end

multi_insert_sql(columns, values) click to toggle source

For PostgreSQL version > 8.2, allow inserting multiple rows at once.

    # File lib/sequel/adapters/shared/postgres.rb, line 689
    def multi_insert_sql(columns, values)
      return super if server_version < 80200

      # postgresql 8.2 introduces support for multi-row insert
      [insert_sql(columns, LiteralString.new('VALUES ' + values.map {|r| literal(Array(r))}.join(COMMA_SEPARATOR)))]
    end

supports_distinct_on?() click to toggle source

DISTINCT ON is a PostgreSQL extension

    # File lib/sequel/adapters/shared/postgres.rb, line 697
    def supports_distinct_on?
      true
    end

supports_modifying_joins?() click to toggle source

PostgreSQL supports modifying joined datasets

    # File lib/sequel/adapters/shared/postgres.rb, line 702
    def supports_modifying_joins?
      true
    end

supports_timestamp_timezones?() click to toggle source

PostgreSQL supports timezones in literal timestamps

    # File lib/sequel/adapters/shared/postgres.rb, line 707
    def supports_timestamp_timezones?
      true
    end

supports_window_functions?() click to toggle source

PostgreSQL 8.4+ supports window functions

    # File lib/sequel/adapters/shared/postgres.rb, line 712
    def supports_window_functions?
      server_version >= 80400
    end

window(name, opts) click to toggle source

Return a clone of the dataset with an addition named window that can be referenced in window functions.

    # File lib/sequel/adapters/shared/postgres.rb, line 717
    def window(name, opts)
      clone(:window=>(@opts[:window]||[]) + [[name, SQL::Window.new(opts)]])
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.