### Home Classes Methods

### Files

- CHANGELOG
- MIT-LICENSE
- README.rdoc
- active_record.rdoc
- advanced_associations.rdoc
- association_basics.rdoc
- bin_sequel.rdoc
- cheat_sheet.rdoc
- code_order.rdoc
- core_extensions.rdoc
- dataset_basics.rdoc
- dataset_filtering.rdoc
- mass_assignment.rdoc
- migration.rdoc
- model_hooks.rdoc
- object_model.rdoc
- opening_databases.rdoc
- postgresql.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.13.0.txt
- 3.14.0.txt
- 3.15.0.txt
- 3.16.0.txt
- 3.17.0.txt
- 3.18.0.txt
- 3.19.0.txt
- 3.2.0.txt
- 3.20.0.txt
- 3.21.0.txt
- 3.22.0.txt
- 3.23.0.txt
- 3.24.0.txt
- 3.25.0.txt
- 3.26.0.txt
- 3.27.0.txt
- 3.28.0.txt
- 3.29.0.txt
- 3.3.0.txt
- 3.30.0.txt
- 3.31.0.txt
- 3.32.0.txt
- 3.33.0.txt
- 3.34.0.txt
- 3.35.0.txt
- 3.36.0.txt
- 3.37.0.txt
- 3.38.0.txt
- 3.39.0.txt
- 3.4.0.txt
- 3.40.0.txt
- 3.41.0.txt
- 3.42.0.txt
- 3.43.0.txt
- 3.44.0.txt
- 3.45.0.txt
- 3.46.0.txt
- 3.47.0.txt
- 3.48.0.txt
- 3.5.0.txt
- 3.6.0.txt
- 3.7.0.txt
- 3.8.0.txt
- 3.9.0.txt
- 4.0.0.txt
- schema_modification.rdoc
- security.rdoc
- sharding.rdoc
- sql.rdoc
- testing.rdoc
- thread_safety.rdoc
- transactions.rdoc
- validations.rdoc
- virtual_rows.rdoc

### Class Index

Quicksearch

- Sequel
- Sequel::ADO
- Sequel::ADO::Access
- Sequel::ADO::Access::AdoSchema
- Sequel::ADO::Access::AdoSchema::Column
- Sequel::ADO::Access::DatabaseMethods
- Sequel::ADO::Access::Dataset
- Sequel::ADO::Database
- Sequel::ADO::Dataset
- Sequel::ADO::MSSQL
- Sequel::ADO::MSSQL::DatabaseMethods
- Sequel::ADO::MSSQL::Dataset
- Sequel::ASTTransformer
- Sequel::Access
- Sequel::Access::DatabaseMethods
- Sequel::Access::DatasetMethods
- Sequel::AdapterNotFound
- Sequel::Amalgalite
- Sequel::Amalgalite::Database
- Sequel::Amalgalite::Dataset
- Sequel::Amalgalite::SequelTypeMap
- Sequel::ArbitraryServers
- Sequel::BasicObject
- Sequel::BeforeHookFailed
- Sequel::CheckConstraintViolation
- Sequel::ColumnsIntrospection
- Sequel::ConnectionPool
- Sequel::ConnectionPool::ClassMethods
- Sequel::ConnectionValidator
- Sequel::ConnectionValidator::Retry
- Sequel::ConstraintValidations
- Sequel::ConstraintValidations::AlterTableGeneratorMethods
- Sequel::ConstraintValidations::CreateTableGeneratorMethods
- Sequel::ConstraintValidations::Generator
- Sequel::ConstraintViolation
- Sequel::CoreRefinements
- Sequel::Cubrid
- Sequel::Cubrid::Database
- Sequel::Cubrid::DatabaseMethods
- Sequel::Cubrid::Dataset
- Sequel::Cubrid::DatasetMethods
- Sequel::DB2
- Sequel::DB2::DB2Error
- Sequel::DB2::Database
- Sequel::DB2::DatabaseMethods
- Sequel::DB2::Dataset
- Sequel::DB2::DatasetMethods
- 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::DatabaseMethods
- Sequel::DataObjects::SQLite
- Sequel::DataObjects::SQLite::DatabaseMethods
- Sequel::Database
- Sequel::Database::DatasetClass
- Sequel::Database::ResetIdentifierMangling
- Sequel::Database::SplitAlterTable
- Sequel::DatabaseConnectionError
- Sequel::DatabaseDisconnectError
- Sequel::DatabaseError
- Sequel::DatabaseQuery
- Sequel::Dataset
- Sequel::Dataset::ArgumentMapper
- Sequel::Dataset::NullDataset
- Sequel::Dataset::Nullifiable
- Sequel::Dataset::Pagination
- Sequel::Dataset::PreparedStatementMethods
- Sequel::Dataset::Query
- Sequel::Dataset::SplitArrayNil
- Sequel::Dataset::StoredProcedureMethods
- Sequel::Dataset::StoredProcedures
- Sequel::Dataset::UnnumberedArgumentMapper
- Sequel::DatasetPagination
- Sequel::DatasetPrinter
- Sequel::DatasetQuery
- Sequel::Deprecation
- Sequel::EmptyArrayIgnoreNulls
- Sequel::EmulateOffsetWithReverseAndCount
- Sequel::EmulateOffsetWithRowNumber
- Sequel::Error
- Sequel::Error::AdapterNotFound
- Sequel::Error::InvalidOperation
- Sequel::Error::InvalidValue
- Sequel::Error::PoolTimeoutError
- Sequel::Error::Rollback
- Sequel::EvalInspect
- Sequel::FilterHaving
- Sequel::Firebird
- Sequel::Firebird::Database
- Sequel::Firebird::DatabaseMethods
- Sequel::Firebird::Dataset
- Sequel::Firebird::DatasetMethods
- Sequel::ForeignKeyConstraintViolation
- Sequel::GraphEach
- Sequel::HashAliases
- Sequel::HookFailed
- Sequel::IBMDB
- Sequel::IBMDB::Connection
- Sequel::IBMDB::Connection::Error
- Sequel::IBMDB::Database
- Sequel::IBMDB::Dataset
- Sequel::IBMDB::Dataset::CallableStatementMethods
- Sequel::IBMDB::Dataset::PreparedStatementMethods
- Sequel::IBMDB::Statement
- Sequel::Inflections
- Sequel::Informix
- Sequel::Informix::Database
- Sequel::Informix::DatabaseMethods
- Sequel::Informix::Dataset
- Sequel::Informix::DatasetMethods
- Sequel::IntegerMigrator
- Sequel::InvalidOperation
- Sequel::InvalidValue
- Sequel::JDBC
- Sequel::JDBC::AS400
- Sequel::JDBC::AS400::DatabaseMethods
- Sequel::JDBC::AS400::Dataset
- Sequel::JDBC::Cubrid
- Sequel::JDBC::Cubrid::DatabaseMethods
- Sequel::JDBC::DB2
- Sequel::JDBC::DB2::DatabaseMethods
- Sequel::JDBC::DB2::Dataset
- Sequel::JDBC::Database
- Sequel::JDBC::Dataset
- Sequel::JDBC::Dataset::PreparedStatementMethods
- Sequel::JDBC::Dataset::StoredProcedureMethods
- Sequel::JDBC::Dataset::TYPE_TRANSLATOR
- Sequel::JDBC::Derby
- Sequel::JDBC::Derby::DatabaseMethods
- Sequel::JDBC::Derby::Dataset
- Sequel::JDBC::Firebird
- Sequel::JDBC::Firebird::DatabaseMethods
- Sequel::JDBC::H2
- Sequel::JDBC::H2::DatabaseMethods
- Sequel::JDBC::H2::Dataset
- Sequel::JDBC::HSQLDB
- Sequel::JDBC::HSQLDB::DatabaseMethods
- Sequel::JDBC::HSQLDB::Dataset
- Sequel::JDBC::Informix
- Sequel::JDBC::Informix::DatabaseMethods
- Sequel::JDBC::JTDS
- Sequel::JDBC::JTDS::DatabaseMethods
- Sequel::JDBC::JTDS::Dataset
- Sequel::JDBC::JavaLang
- Sequel::JDBC::JavaSQL
- Sequel::JDBC::JavaxNaming
- Sequel::JDBC::MSSQL
- Sequel::JDBC::MSSQL::DatabaseMethods
- Sequel::JDBC::MySQL
- Sequel::JDBC::MySQL::DatabaseMethods
- Sequel::JDBC::Oracle
- Sequel::JDBC::Oracle::DatabaseMethods
- Sequel::JDBC::Oracle::Dataset
- Sequel::JDBC::Postgres
- Sequel::JDBC::Postgres::DatabaseMethods
- Sequel::JDBC::Postgres::Dataset
- Sequel::JDBC::Postgres::Dataset::PGArrayConverter
- Sequel::JDBC::Progress
- Sequel::JDBC::Progress::DatabaseMethods
- Sequel::JDBC::SQLServer
- Sequel::JDBC::SQLServer::DatabaseMethods
- Sequel::JDBC::SQLServer::DatabaseMethods::MetadataDatasetMethods
- Sequel::JDBC::SQLite
- Sequel::JDBC::SQLite::DatabaseMethods
- Sequel::JDBC::Transactions
- Sequel::LiteralString
- Sequel::LooserTypecasting
- Sequel::MSSQL
- Sequel::MSSQL::DatabaseMethods
- Sequel::MSSQL::DatasetMethods
- Sequel::Metaprogramming
- Sequel::Migration
- Sequel::MigrationAlterTableReverser
- Sequel::MigrationDSL
- Sequel::MigrationReverser
- Sequel::Migrator
- Sequel::Migrator::Error
- Sequel::Migrator::NotCurrentError
- Sequel::Mock
- Sequel::Mock::Connection
- Sequel::Mock::Database
- Sequel::Mock::Dataset
- Sequel::Model
- Sequel::Model::Associations
- Sequel::Model::Associations::AssociationDatasetMethods
- Sequel::Model::Associations::AssociationReflection
- Sequel::Model::Associations::ClassMethods
- Sequel::Model::Associations::DatasetMethods
- Sequel::Model::Associations::EagerGraphLoader
- 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::DatasetModule
- Sequel::Model::Errors
- Sequel::Model::InstanceMethods
- Sequel::MySQL
- Sequel::MySQL::Database
- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::Dataset
- Sequel::MySQL::DatasetMethods
- Sequel::MySQL::PreparedStatements
- Sequel::MySQL::PreparedStatements::DatabaseMethods
- Sequel::MySQL::PreparedStatements::DatasetMethods
- Sequel::MySQL::PreparedStatements::DatasetMethods::CallableStatementMethods
- Sequel::MySQL::PreparedStatements::DatasetMethods::PreparedStatementMethods
- Sequel::MySQL::PreparedStatements::DatasetMethods::StoredProcedureMethods
- Sequel::Mysql2
- Sequel::Mysql2::Database
- Sequel::Mysql2::Dataset
- Sequel::NamedTimezones
- Sequel::NamedTimezones::DatabaseMethods
- Sequel::NoExistingObject
- Sequel::NoMatchingRow
- Sequel::NotNullConstraintViolation
- 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::Dataset::ArgumentMapper
- Sequel::Oracle::Dataset::BindArgumentMethods
- Sequel::Oracle::Dataset::PreparedStatementMethods
- Sequel::Oracle::DatasetMethods
- Sequel::Plugins
- Sequel::Plugins::ActiveModel
- Sequel::Plugins::ActiveModel::ClassMethods
- Sequel::Plugins::ActiveModel::Errors
- Sequel::Plugins::ActiveModel::InstanceMethods
- Sequel::Plugins::AfterInitialize
- Sequel::Plugins::AfterInitialize::ClassMethods
- Sequel::Plugins::AfterInitialize::InstanceMethods
- Sequel::Plugins::AssociationAutoreloading
- Sequel::Plugins::AssociationDependencies
- Sequel::Plugins::AssociationDependencies::ClassMethods
- Sequel::Plugins::AssociationDependencies::InstanceMethods
- Sequel::Plugins::AssociationPks
- Sequel::Plugins::AssociationPks::ClassMethods
- Sequel::Plugins::AssociationPks::InstanceMethods
- Sequel::Plugins::AssociationProxies
- Sequel::Plugins::AssociationProxies::AssociationProxy
- Sequel::Plugins::AssociationProxies::ClassMethods
- Sequel::Plugins::AutoValidations
- Sequel::Plugins::AutoValidations::ClassMethods
- Sequel::Plugins::AutoValidations::InstanceMethods
- Sequel::Plugins::BlacklistSecurity
- Sequel::Plugins::BlacklistSecurity::ClassMethods
- Sequel::Plugins::BlacklistSecurity::InstanceMethods
- Sequel::Plugins::BlacklistSecurity::InstanceMethods::ExceptionList
- 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::ConstraintValidations
- Sequel::Plugins::ConstraintValidations::ClassMethods
- Sequel::Plugins::ConstraintValidations::DatabaseMethods
- Sequel::Plugins::ConstraintValidations::InstanceMethods
- Sequel::Plugins::DatasetAssociations
- Sequel::Plugins::DatasetAssociations::ClassMethods
- Sequel::Plugins::DatasetAssociations::DatasetMethods
- Sequel::Plugins::DefaultsSetter
- Sequel::Plugins::DefaultsSetter::ClassMethods
- Sequel::Plugins::DefaultsSetter::InstanceMethods
- Sequel::Plugins::Dirty
- Sequel::Plugins::Dirty::InstanceMethods
- Sequel::Plugins::EagerEach
- Sequel::Plugins::EagerEach::DatasetMethods
- Sequel::Plugins::ErrorSplitter
- Sequel::Plugins::ErrorSplitter::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::InputTransformer
- Sequel::Plugins::InputTransformer::ClassMethods
- Sequel::Plugins::InputTransformer::InstanceMethods
- Sequel::Plugins::InstanceFilters
- Sequel::Plugins::InstanceFilters::InstanceMethods
- Sequel::Plugins::InstanceHooks
- Sequel::Plugins::InstanceHooks::InstanceMethods
- Sequel::Plugins::JsonSerializer
- Sequel::Plugins::JsonSerializer::ClassMethods
- Sequel::Plugins::JsonSerializer::DatasetMethods
- Sequel::Plugins::JsonSerializer::InstanceMethods
- Sequel::Plugins::JsonSerializer::Literal
- Sequel::Plugins::LazyAttributes
- Sequel::Plugins::LazyAttributes::ClassMethods
- Sequel::Plugins::LazyAttributes::InstanceMethods
- Sequel::Plugins::List
- Sequel::Plugins::List::ClassMethods
- Sequel::Plugins::List::InstanceMethods
- Sequel::Plugins::ManyThroughMany
- Sequel::Plugins::ManyThroughMany::ClassMethods
- Sequel::Plugins::ManyThroughMany::DatasetMethods
- Sequel::Plugins::ManyThroughMany::ManyThroughManyAssociationReflection
- Sequel::Plugins::ManyToOnePkLookup
- Sequel::Plugins::NestedAttributes
- Sequel::Plugins::NestedAttributes::ClassMethods
- Sequel::Plugins::NestedAttributes::InstanceMethods
- Sequel::Plugins::OptimisticLocking
- Sequel::Plugins::OptimisticLocking::ClassMethods
- Sequel::Plugins::OptimisticLocking::InstanceMethods
- Sequel::Plugins::PgArrayAssociations
- Sequel::Plugins::PgArrayAssociations::ClassMethods
- Sequel::Plugins::PgArrayAssociations::DatasetMethods
- Sequel::Plugins::PgArrayAssociations::ManyToPgArrayAssociationReflection
- Sequel::Plugins::PgArrayAssociations::PgArrayToManyAssociationReflection
- Sequel::Plugins::PgRow
- Sequel::Plugins::PgRow::ClassMethods
- Sequel::Plugins::PgRow::DatabaseMethods
- Sequel::Plugins::PgRow::InstanceMethods
- Sequel::Plugins::PgTypecastOnLoad
- Sequel::Plugins::PgTypecastOnLoad::ClassMethods
- Sequel::Plugins::PgTypecastOnLoad::InstanceMethods
- Sequel::Plugins::PreparedStatements
- Sequel::Plugins::PreparedStatements::ClassMethods
- Sequel::Plugins::PreparedStatements::InstanceMethods
- Sequel::Plugins::PreparedStatementsAssociations
- Sequel::Plugins::PreparedStatementsAssociations::ClassMethods
- Sequel::Plugins::PreparedStatementsAssociations::InstanceMethods
- Sequel::Plugins::PreparedStatementsSafe
- Sequel::Plugins::PreparedStatementsSafe::ClassMethods
- Sequel::Plugins::PreparedStatementsSafe::InstanceMethods
- Sequel::Plugins::PreparedStatementsWithPk
- Sequel::Plugins::PreparedStatementsWithPk::ClassMethods
- Sequel::Plugins::PreparedStatementsWithPk::DatasetMethods
- Sequel::Plugins::RcteTree
- Sequel::Plugins::Schema
- Sequel::Plugins::Schema::ClassMethods
- Sequel::Plugins::Scissors
- Sequel::Plugins::Scissors::ClassMethods
- Sequel::Plugins::Serialization
- Sequel::Plugins::Serialization::ClassMethods
- Sequel::Plugins::Serialization::InstanceMethods
- Sequel::Plugins::SerializationModificationDetection
- Sequel::Plugins::SerializationModificationDetection::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::StaticCache
- Sequel::Plugins::StaticCache::ClassMethods
- Sequel::Plugins::StringStripper
- Sequel::Plugins::StringStripper::ClassMethods
- 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::Tree
- Sequel::Plugins::Tree::ClassMethods
- Sequel::Plugins::Tree::InstanceMethods
- Sequel::Plugins::Tree::SingleRoot
- Sequel::Plugins::Tree::SingleRoot::ClassMethods
- Sequel::Plugins::Tree::SingleRoot::InstanceMethods
- Sequel::Plugins::Tree::TreeMultipleRootError
- Sequel::Plugins::TypecastOnLoad
- Sequel::Plugins::TypecastOnLoad::ClassMethods
- Sequel::Plugins::TypecastOnLoad::InstanceMethods
- Sequel::Plugins::UnlimitedUpdate
- Sequel::Plugins::UnlimitedUpdate::InstanceMethods
- Sequel::Plugins::UpdatePrimaryKey
- 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::Plugins::XmlSerializer
- Sequel::Plugins::XmlSerializer::ClassMethods
- Sequel::Plugins::XmlSerializer::DatasetMethods
- Sequel::Plugins::XmlSerializer::InstanceMethods
- Sequel::PoolTimeout
- Sequel::Postgres
- Sequel::Postgres::Adapter
- Sequel::Postgres::AlterTableGenerator
- Sequel::Postgres::ArrayOp
- Sequel::Postgres::ArrayOpMethods
- Sequel::Postgres::CreateTableGenerator
- 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::Postgres::ExclusionConstraintViolation
- Sequel::Postgres::HStore
- Sequel::Postgres::HStore::DatabaseMethods
- Sequel::Postgres::HStore::Parser
- Sequel::Postgres::HStoreOp
- Sequel::Postgres::HStoreOpMethods
- Sequel::Postgres::InetDatabaseMethods
- Sequel::Postgres::InetDatasetMethods
- Sequel::Postgres::IntervalDatabaseMethods
- Sequel::Postgres::IntervalDatabaseMethods::Parser
- Sequel::Postgres::IntervalDatasetMethods
- Sequel::Postgres::JSONArray
- Sequel::Postgres::JSONDatabaseMethods
- Sequel::Postgres::JSONHash
- Sequel::Postgres::JSONOp
- Sequel::Postgres::JSONOpMethods
- Sequel::Postgres::PGArray
- Sequel::Postgres::PGArray::Creator
- Sequel::Postgres::PGArray::DatabaseMethods
- Sequel::Postgres::PGArray::JSONCreator
- Sequel::Postgres::PGArray::Parser
- Sequel::Postgres::PGRange
- Sequel::Postgres::PGRange::DatabaseMethods
- Sequel::Postgres::PGRange::DatasetMethods
- Sequel::Postgres::PGRange::Parser
- Sequel::Postgres::PGRow
- Sequel::Postgres::PGRow::ArrayRow
- Sequel::Postgres::PGRow::DatabaseMethods
- Sequel::Postgres::PGRow::HashRow
- Sequel::Postgres::PGRow::Parser
- Sequel::Postgres::PGRow::Splitter
- Sequel::Postgres::PGRowOp
- Sequel::Postgres::PGRowOp::ExpressionMethods
- Sequel::Postgres::RangeOp
- Sequel::Postgres::RangeOpMethods
- Sequel::PrettyTable
- Sequel::Progress
- Sequel::Progress::DatabaseMethods
- Sequel::Progress::DatasetMethods
- Sequel::Qualifier
- Sequel::QueryLiterals
- 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::Builders
- 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::DateAdd
- Sequel::SQL::DateAdd::DatasetMethods
- Sequel::SQL::DelayedEvaluation
- Sequel::SQL::EmulatedFunction
- Sequel::SQL::Expression
- Sequel::SQL::Function
- Sequel::SQL::GenericExpression
- Sequel::SQL::Identifier
- Sequel::SQL::InequalityMethods
- Sequel::SQL::JoinClause
- Sequel::SQL::JoinOnClause
- Sequel::SQL::JoinUsingClause
- Sequel::SQL::NegativeBooleanConstant
- Sequel::SQL::NumericExpression
- Sequel::SQL::NumericMethods
- Sequel::SQL::OperatorBuilders
- Sequel::SQL::OrderMethods
- Sequel::SQL::OrderedExpression
- Sequel::SQL::PlaceholderLiteralString
- Sequel::SQL::QualifiedIdentifier
- Sequel::SQL::QualifyingMethods
- Sequel::SQL::StringConcatenationMethods
- Sequel::SQL::StringExpression
- Sequel::SQL::StringMethods
- Sequel::SQL::Subscript
- Sequel::SQL::SubscriptMethods
- Sequel::SQL::ValueList
- Sequel::SQL::VirtualRow
- Sequel::SQL::Window
- Sequel::SQL::WindowFunction
- Sequel::SQL::Wrapper
- Sequel::SQLTime
- Sequel::SQLite
- Sequel::SQLite::Database
- Sequel::SQLite::DatabaseMethods
- Sequel::SQLite::Dataset
- Sequel::SQLite::Dataset::ArgumentMapper
- Sequel::SQLite::Dataset::BindArgumentMethods
- Sequel::SQLite::Dataset::PreparedStatementMethods
- Sequel::SQLite::DatasetMethods
- Sequel::Schema
- Sequel::Schema::AlterTableGenerator
- Sequel::Schema::CreateTableGenerator
- Sequel::Schema::Generator
- Sequel::SchemaCaching
- Sequel::SchemaDumper
- Sequel::SelectRemove
- Sequel::Sequel3DatasetMethods
- Sequel::SerializationFailure
- Sequel::ServerBlock
- Sequel::SetOverrides
- Sequel::ShardedSingleConnectionPool
- Sequel::ShardedThreadedConnectionPool
- Sequel::SimpleMigration
- Sequel::SingleConnectionPool
- Sequel::Swift
- Sequel::Swift::Database
- Sequel::Swift::Dataset
- Sequel::Swift::MySQL
- Sequel::Swift::MySQL::DatabaseMethods
- Sequel::Swift::MySQL::Dataset
- Sequel::Swift::Postgres
- Sequel::Swift::Postgres::DatabaseMethods
- Sequel::Swift::SQLite
- Sequel::Swift::SQLite::DatabaseMethods
- Sequel::Swift::SQLite::Dataset
- Sequel::ThreadLocalTimezones
- Sequel::ThreadedConnectionPool
- Sequel::ThreadedServerBlock
- Sequel::TimestampMigrator
- Sequel::Timezones
- Sequel::TinyTDS
- Sequel::TinyTDS::Database
- Sequel::TinyTDS::Dataset
- Sequel::TinyTDS::Dataset::ArgumentMapper
- Sequel::TinyTDS::Dataset::PreparedStatementMethods
- Sequel::ToDot
- Sequel::ToDot::DatasetMethods
- Sequel::UnbindDuplicate
- Sequel::Unbinder
- Sequel::UndefinedAssociation
- Sequel::UniqueConstraintViolation
- Sequel::UnthreadedServerBlock
- Sequel::ValidationFailed
- String
- String::Inflections
- Array
- FalseClass
- Hash
- NilClass
- Numeric
- Object
- PGconn
- PGresult
- Range
- Symbol
- TrueClass

No matching classes.

# Sequel for SQL Users

One of the main benefits of Sequel is that it doesn't require the user to know SQL in order to use it, though SQL knowledge is certainly helpful. Unlike most other Sequel documentation, this guide assumes you know SQL, and provides an easy way to discover how to do something in Sequel given the knowledge of how to do so in SQL.

## You Can Just Use SQL

With Sequel, it's very easy to just use SQL for your queries. If learning Sequel's DSL seems like a waste of time, you are certainly free to write all your queries in SQL. Sequel uses a few different methods depending on the type of query you are doing.

### SELECT

For SELECT queries, you should probably use `Database#fetch` with a string and a block:

    DB.fetch("SELECT * FROM albums") do |row|
      puts row[:name]
    end

`Database#fetch` will take the query you give it, execute it on the database, and yield a hash with column symbol keys for each row returned. If you want to use some placeholder variables, you can set the placeholders with ? and add the arguments to fetch:

    DB.fetch("SELECT * FROM albums WHERE name LIKE ?", 'A%') do |row|
      puts row[:name]
    end

You can also use named placeholders by starting the placeholder with a colon, and using a hash for the argument:

    DB.fetch("SELECT * FROM albums WHERE name LIKE :pattern", :pattern=>'A%') do |row|
      puts row[:name]
    end

This can be helpful for long queries where it is difficult to match the ? with the arguments.

What Sequel actually does internally is two separate things. It first creates a dataset representing the query, and then it executes the dataset's SQL code to retrieve the objects. Often, you want to define a dataset at some point, but not execute it till later. You can do this by leaving off the block, and storing the dataset in a variable:

    ds = DB.fetch("SELECT * FROM albums")

Then, when you want to retrieve the rows later, you can call `each` on the dataset to retrieve the rows:

    ds.each{|r| puts r[:name]}

You should note that `Database#[]` calls `Database#fetch` if a string is provided, so you can also do:

    ds = DB["SELECT * FROM albums"]
    ds.each{|r| puts r[:name]}

However, note that `Database#[]` cannot take a block directly, you have to call `each` on the returned dataset. There are plenty of other methods besides `each`, one is `all` which returns all records as an array:

    DB["SELECT * FROM albums"].all # [{:id=>1, :name=>'RF', ...}, ...]

### INSERT, UPDATE, DELETE

INSERT, UPDATE, and DELETE all work the same way. You first create the dataset with the SQL you want to execute using `Database#[]`:

    insert_ds = DB["INSERT INTO albums (name) VALUES (?)", 'RF']
    update_ds = DB["UPDATE albums SET name = ? WHERE name = ?", 'MO', 'RF']
    delete_ds = DB["DELETE FROM albums WHERE name = ?", 'MO']

Then, you call the `insert`, `update`, or `delete` method on the returned dataset:

    insert_ds.insert
    update_ds.update
    delete_ds.delete

`update` and `delete` should return the number of rows affected, and `insert` should return the autogenerated primary key integer for the row inserted (if any).

### Other Queries

All other queries such as TRUNCATE, CREATE TABLE, and ALTER TABLE should be executed using `Database#run`:

    DB.run "CREATE TABLE albums (id integer primary key, name varchar(255))"

You can also use `Database#<<`:

    DB << "ALTER TABLE albums ADD COLUMN copies_sold INTEGER"

### Other Places

Almost everywhere in Sequel, you can drop down to literal SQL by providing a literal string, which you can create with `Sequel.lit`:

    DB[:albums].select('name') # SELECT 'name' FROM albums
    DB[:albums].select(Sequel.lit('name')) # SELECT name FROM albums

For a simpler way of creating literal strings, you can also use the core_extensions extension, which adds the `String#lit` method, and other methods that integrate Sequel's DSL with the ruby language:

    DB[:albums].select('name'.lit)

So you can use Sequel's DSL everywhere you find it helpful, and fallback to literal SQL if the DSL can't do what you want or you just find literal SQL easier.

## Translating SQL Expressions into Sequel

The rest of this guide assumes you want to use Sequel's DSL to represent your query, that you know how to write the query in SQL, but you aren't sure how to write it in Sequel's DSL.

This section will describe how specific SQL expressions are handled in Sequel. The next section will discuss how to create queries by using method chaining on datasets.

### `Database#literal`

It's important to get familiar with the `Database#literal` method, which will return the SQL that will be used for a given expression:

    DB.literal(1)
    # => "1"
    DB.literal(:column)
    # => "\"column\""
    DB.literal('string')
    # => "'string'"

Try playing around to see how different objects get literalized into SQL

### Database Loggers

Some Sequel methods handle literalization slightly differently than `Database#literal`. If you want to see all SQL queries that Sequel is sending to the database, you should add a database logger:

    DB.loggers << Logger.new($stdout)

Now that you know how to see what SQL is being used, let's jump in and see how to map SQL syntax to Sequel syntax:

### Identifiers

In Sequel, SQL identifiers are usually specified as ruby symbols:

    :column # "column"

As you can see, Sequel quotes identifiers by default. Depending on your database, it may uppercase them by default as well:

    :column # "COLUMN" on some databases

A plain symbol is usually treated as an unqualified identifier. However, if you are using multiple tables in a query, and you want to reference a column in one of the tables that has the same name as a column in another one of the tables, you need to qualify that reference. There's two main ways in Sequel to do that. The first is implicit qualification inside the symbol, using the double underscore:

    :table__column # "table"."column"

Note that you can't use a period to separate them:

    :table.column # calls the column method on the symbol

Also note that specifying the period inside the symbol doesn't work if you are quoting identifiers:

    :"table.column" # "table.column"

The other way to qualify an identifier is to use the `Sequel.qualify` with the table and column symbols:

    Sequel.qualify(:table, :column) # "table"."column"

Another way to generate identifiers is to use Sequel's virtual row support:

    DB[:albums].select{name} # SELECT "name" FROM "albums"
    DB[:albums].select{albums__name} # SELECT "albums"."name" FROM "albums"

### Numbers

In general, ruby numbers map directly to SQL numbers:

    # Integers
    1 # 1
    -1 # -1

    # Floats
    1.5 # 1.5

    # BigDecimals
    BigDecimal.new('1000000.123091029') # 1000000.123091029

### Strings

In general, ruby strings map directly to SQL strings:

    'name' # 'name'
    "name" # 'name'

### Aliasing

Sequel allows for implicit aliasing in column symbols using the triple underscore:

    :column___alias # "column" AS "alias"

You can combine this with implicit qualification:

    :table__column___alias # "table"."column" AS "alias"

You can also use the `Sequel.as` method to create an alias, and the `as` method on most Sequel-specific expression objects:

    Sequel.as(:column, :alias) # "column" AS "alias"
    Sequel.qualify(:table, :column).as(:alias) # "table"."column" AS "alias"

### Functions

The easiest way to use SQL functions is via a virtual row:

    DB[:albums].select{func{}} # SELECT func() FROM "albums"
    DB[:albums].select{func(col1, col2)} # SELECT func("col1", "col2") FROM "albums"

You can also use the `Sequel.function` method on the symbol that contains the function name:

    Sequel.function(:func) # func()
    Sequel.function(:func, :col1, :col2) # func("col1", "col2")

### Aggregate Functions

Aggregate functions work the same way as normal functions, since they share the same syntax:

    Sequel.function(:sum, :column) # sum(column)

However, if you want to use the DISTINCT modifier to an aggregate function, you either have to use literal SQL or a virtual row block:

    Sequel.function(:sum, Sequel.lit('DISTINCT column')) # sum(DISTINCT column)
    DB[:albums].select{sum(:distinct, :column){}} # SELECT sum(DISTINCT column) FROM albums

If you want to use the wildcard as the sole argument of the aggregate function, you again have to use literal SQL or a virtual row block:

    Sequel.function(:count, Sequel.lit('*')) # count(*)
    DB[:albums].select{count(:*){}} # SELECT count(*) FROM albums

Note that Sequel provides helper methods for aggregate functions such as `count`, `sum`, `min`, `max`, `avg`, and `group_and_count`, which handle common uses of aggregate functions.

### Window Functions

If the database supports window functions, Sequel can handle them using a virtual row block:

    DB[:albums].select{function(:over){}}
    # SELECT function() OVER () FROM albums

    DB[:albums].select{count(:over, :*=>true){}}
    # SELECT count(*) OVER () FROM albums

    DB[:albums].select{function(:over, :args=>col1, :partition=>col2, :order=>col3){}}
    # SELECT function(col1) OVER (PARTITION BY col2 ORDER BY col3) FROM albums

    DB[:albums].select{function(:over, :args=>[c1, c2], :partition=>[c3, c4], :order=>[c5, c6]){}}
    # SELECT function(c1, c2) OVER (PARTITION BY c3, c4 ORDER BY c5, c6) FROM albums

### Equality Operator (=)

Sequel uses hashes to specify equality:

    {:column=>1} # ("column" = 1)

You can also specify this as an array of two element arrays:

    [[:column, 1]] # ("column" = 1)

### Not Equal Operator (!=)

You can specify a not equals condition by inverting the hash or array of two element arrays using `Sequel.negate` or `Sequel.~`:

    Sequel.negate(:column => 1)   # ("column" != 1)
    Sequel.negate([[:column, 1]]) # ("column" != 1)
    Sequel.~(:column => 1)        # ("column" != 1)
    Sequel.~([[:column, 1]])      # ("column" != 1)

The difference between the two is that negate only works on hashes and arrays of element arrays, and it negates all entries in the, while ~ does a general inversion. This is best shown by an example with multiple entries:

    Sequel.negate(:column => 1, :foo => 2)   # (("column" != 1) AND (foo != 2))
    Sequel.~(:column => 1, :foo => 2)        # (("column" != 1) OR (foo != 2))

The most common need for not equals is in filters, in which case you can use the `exclude` method:

    DB[:albums].exclude(:column=>1) # SELECT * FROM "albums" WHERE ("column" != 1)

Note that `exclude` does a generalized inversion, similar to `Sequel.~`.

### Inclusion and Exclusion Operators (IN, NOT IN)

Sequel also uses hashes to specify inclusion, and inversions of those hashes to specify exclusion:

    {:column=>[1, 2, 3]} # ("column" IN (1, 2, 3))
    Sequel.~(:column=>[1, 2, 3]) # ("column" NOT IN (1, 2, 3))

As you may have guessed, Sequel switches from an = to an IN when the hash value is an array. It also does this for datasets, which easily allows you to test for inclusion and exclusion in a subselect:

    {:column=>DB[:albums].select(:id)} # ("column" IN (SELECT "id" FROM "albums"))
    Sequel.~(:column=>DB[:albums].select(:id)) # ("column" NOT IN (SELECT "id" FROM "albums"))

Sequel also supports the SQL EXISTS operator using `Dataset#exists`:

    DB[:albums].exists # EXISTS (SELECT * FROM albums)

### Identity Operators (IS, IS NOT)

Hashes in Sequel use IS if the value is true, false, or nil:

    {:column=>nil) # ("column" IS NULL)
    {:column=>true) # ("column" IS TRUE)
    {:column=>false) # ("column" IS FALSE)

Negation works the same way as it does for equality and inclusion:

    Sequel.~(:column=>nil) # ("column" IS NOT NULL)
    Sequel.~(:column=>true) # ("column" IS NOT TRUE)
    Sequel.~(:column=>false) # ("column" IS NOT FALSE)

### Inversion Operator (NOT)

Sequel's general inversion operator is ~, which works on symbols and most Sequel-specific expression objects:

    Sequel.~(:column) # NOT "column"

Note that ~ will actually apply the inversion operation to the underlying object, which is why

    Sequel.~(:column=>1)

produces `(column != 1)` instead of `NOT (column = 1)`.

### Inequality Operators (< > <= >=)

Sequel defines the inequality operators directly on most Sequel-specific expression objects:

    Sequel.qualify(:table, :column) > 1 # ("table"."column" > 1)
    Sequel.qualify(:table, :column) < 1 # ("table"."column" < 1)
    Sequel.function(:func) >= 1 # (func() >= 1)
    Sequel.function(:func, :column) <= 1 # (func("column") <= 1)

If you want to use them on a symbol, you should call `Sequel.expr` with the symbol:

    Sequel.expr(:column) > 1 # ("column" > 1)

A common use of virtual rows is to handle inequality operators:

    DB[:albums].where{col1 > col2} # SELECT * FROM "albums" WHERE ("col1" > "col2")

### Standard Mathematical Operators (+ - * /)

The standard mathematical operates are defined on most Sequel-specific expression objects:

    Sequel.expr(:column) + 1 # "column" + 1
    Sequel.expr(:table__column) - 1 # "table"."column" - 1
    Sequel.qualify(:table, :column) * 1 # "table"."column" * 1
    Sequel.expr(:column) / 1 # "column" / 1

You can also call the operator methods directly on the Sequel module:

    Sequel.+(:column, 1) # "column" + 1
    Sequel.-(:table__column, 1) # "table"."column" - 1
    Sequel.*(Sequel.qualify(:table, :column), 1) # "table"."column" * 1
    Sequel./(:column, 1) # "column" / 1

Note that the following does not work:

    1 + Sequel.expr(:column) # raises TypeError

For commutative operates such as + and *, this isn't a problem as you can just reorder, but non-commutative operators such as - and / cannot be expressed directly. The solution is to use one of the methods on the Sequel module:

    Sequel.expr(1) / :column # (1 / "column")
    Sequel./(1, :column) # (1 / "column")

### Boolean Operators (AND OR)

Sequel defines the & and | methods on most Sequel-specific expression objects to handle AND and OR:

    Sequel.expr(:column1) & :column2 # ("column1" AND "column2")
    Sequel.expr(:column1=>1) | {:column2=>2} # (("column1" = 1) OR ("column2" = 2))
    (Sequel.function(:func) > 1) & :column3 # ((func() > 1) AND "column3")

Note the use of parentheses in the last statement. If you omit them, you won't get what you expect. Because & has higher precedence than >

    Sequel.function(:func) > 1 & :column3

is parsed as:

    Sequel.function(:func) > (1 & :column3)

You and also use the `Sequel.&` and `Sequel.|` methods:

    Sequel.&(:column1, :column2) # ("column1" AND "column2")
    Sequel.|({:column1=>1}, {:column2=>2}) # (("column1" = 1) OR ("column2" = 2))

You can use hashes and arrays of two element arrays to specify AND and OR with equality conditions:

    {:column1=>1, :column2=>2} # (("column1" = 1) AND ("column2" = 2))
    [[:column1, 1], [:column2, 2]] # (("column1" = 1) AND ("column2" = 2))

As you can see, these literalize with ANDs by default. You can use the `Sequel.or` method to use OR instead:

    Sequel.or(:column1=>1, :column2=>2) # (("column1" = 1) OR ("column2" = 2))

You've already seen the `Sequel.negate` method, which will use ANDs if multiple entries are used:

    Sequel.negate(:column1=>1, :column2=>2) # (("column1" != 1) AND ("column2" != 2))

To negate while using ORs, the `Sequel.~` operator can be used:

    Sequel.~(:column1=>1, :column2=>2) # (("column1" != 1) OR ("column2" != 2))

Note again that `Dataset#exclude` uses ~, not `negate`:

    DB[:albums].exclude(:column1=>1, :column2=>2) # SELECT * FROM "albums" WHERE (("column" != 1) OR ("column2" != 2))

### Casts

Casting in Sequel is done with the `cast` method, which is available on most of the Sequel-specific expression objects:

    Sequel.expr(:name).cast(:text) # CAST("name" AS text)
    Sequel.expr('1').cast(:integer) # CAST('1' AS integer)
    Sequel.qualify(:table, :column).cast(:date) # CAST("table"."column" AS date)

You can also use the `Sequel.cast` method:

    Sequel.cast(:name, :text) # CAST("name" AS text)

### Bitwise Mathematical Operators (& | ^ << >> ~)

Sequel allows the use of bitwise mathematical operators on Sequel::SQL::NumericExpression objects:

    Sequel.expr(:number) + 1 # => #<Sequel::SQL::NumericExpression ...>
    (Sequel.expr(:number) + 1) & 5 # (("number" + 1) & 5)

As you can see, when you use the + operator on a symbol, you get a NumericExpression. You can turn an expression a NumericExpression using `sql_number`:

    Sequel.expr(:number).sql_number | 5 # ("number" | 5)
    Sequel.function(:func).sql_number << 7 # (func() << 7)
    Sequel.cast(:name, :integer).sql_number >> 8 # (CAST("name" AS integer) >> 8)

Sequel allows you to do the cast and conversion at the same time via `cast_numeric`:

    Sequel.expr(:name).cast_numeric ^ 9 # (CAST("name" AS integer) ^ 9)

Note that &, |, and ~ are already defined to do AND, OR, and NOT on most expressions, so if you want to use the bitwise operators, you need to make sure that they are converted first:

    ~Sequel.expr(:name) # NOT "name"
    ~Sequel.expr(:name).sql_number # ~"name"

### String Operators (||, LIKE, Regexp)

Sequel allows the use of the string concatenation operator on Sequel::SQL::StringExpression objects, which can be created using the `sql_string` method on an expression:

    Sequel.expr(:name).sql_string + ' - Name' # ("name" || ' - Name')

Just like for the bitwise operators, Sequel allows you do do the cast and conversion at the same time via `cast_string`:

    Sequel.expr(:number).cast_string + ' - Number' # (CAST(number AS varchar(255)) || ' - Number')

Note that similar to the mathematical operators, you cannot switch the order the expression and have it work:

    'Name - ' + Sequel.expr(:name).sql_string # raises TypeError

Just like for the mathematical operators, you can use `Sequel.expr` to wrap the object:

    Sequel.expr('Name - ') + :name # ('Name - ' || "name")

The `Sequel.join` method concatenates all of the elements in the array:

    Sequel.join(['Name', :name]) # ('Name' || "name")

Just like ruby's `String#join`, you can provide an argument for a string used to join each element:

    Sequel.join(['Name', :name], ' - ') # ('Name' || ' - ' || "name")

For the LIKE operator, Sequel defines the `like` and `ilike` methods on most Sequel-specific expression objects:

    Sequel.expr(:name).like('A%') # ("name" LIKE 'A%')
    Sequel.expr(:name).ilike('A%') # ("name" ILIKE 'A%')

You can also use the `Sequel.like` and `Sequel.ilike` methods:

    Sequel.like(:name, 'A%') # ("name" LIKE 'A%')
    Sequel.ilike(:name, 'A%') # ("name" ILIKE 'A%')

Note the above syntax for ilike, while Sequel's default, is specific to PostgreSQL. However, most other adapters override the behavior. For example, on MySQL, Sequel uses LIKE BINARY for `like`, and LIKE for `ilike`. If the database supports both case sensitive and case insensitive LIKE, then `like` will use a case sensitive LIKE, and `ilike` will use a case insensitive LIKE.

Inverting the LIKE operator works like other inversions:

    ~Sequel.like(:name, 'A%') # ("name" NOT LIKE 'A%')

Sequel also supports SQL regular expressions on MySQL and PostgreSQL. You can use these by passing a ruby regular expression to `like` or `ilike`, or by making the regular expression a hash value:

    Sequel.like(:name, /^A/) # ("name" ~ '^A')
    ~Sequel.ilike(:name, /^A/) # ("name" !~* '^A')
    {:name=>/^A/i} # ("name" ~* '^A')
    Sequel.~(:name=>/^A/) # ("name" !~ '^A')

Note that using `ilike` with a regular expression will always make the regexp case insensitive. If you use `like` or the hash with regexp value, it will only be case insensitive if the Regexp itself is case insensitive.

### Order Specifications (ASC, DESC)

Sequel supports specifying ascending or descending order using the asc+ and `desc` method on most Sequel-specific expression objects:

    Sequel.expr(:column).asc # "column" ASC
    Sequel.expr(:column).qualify(:table).desc # "table"."column" DESC

You can also use the `Sequel.asc` and `Sequel.desc` methods:

    Sequel.asc(:column) # "column" ASC
    Sequel.desc(Sequel.expr(:column).qualify(:table)) # "table"."column" DESC

On some databases, you can specify null ordering:

    Sequel.asc(:column, :nulls=>:first) # "column" ASC NULLS FIRST
    Sequel.desc(Sequel.expr(:column).qualify(:table), :nulls=>:last) # "table"."column" DESC NULLS LAST

### All Columns (.*)

To select all columns in a table, Sequel supports the * method on identifiers without an argument:

    Sequel.expr(:table).* # "table".*

### CASE statements

Sequel allows the easy production of SQL CASE statements using the `Sequel.case` method. The first argument is a hash or array of two element arrays representing the conditions, the second argument is the default value (ELSE). The keys of the hash (or first element in each array) is the WHEN condition, and the values of the hash (or second element in each array) is the THEN result. Here are some examples:

    Sequel.case({:column=>1, 0) # (CASE WHEN "column" THEN 1 ELSE 0 END)
    Sequel.case([[column, 1]], 0) # (CASE WHEN "column" THEN 1 ELSE 0 END)
    Sequel.case({{:column=>nil}=>1}, 0) # (CASE WHEN (column IS NULL) THEN 1 ELSE 0 END)

If the hash or array has multiple arguments, multiple WHEN clauses are used:

    Sequel.case({:c=>1, :d=>2}, 0) # (CASE WHEN "c" THEN 1 WHEN "d" THEN 2 ELSE 0 END)
    Sequel.case([[:c, 1], [:d, 2]], 0) # (CASE WHEN "c" THEN 1 WHEN "d" THEN 2 ELSE 0 END)

If you provide a 3rd argument to `Sequel.case`, it goes between CASE and WHEN:

    Sequel.case({2=>1, 3=>5}, 0, :column) # (CASE column WHEN 2 THEN 1 WHEN 3 THEN 5 ELSE 0 END)

### Subscripts/Array Access ([])

Sequel supports SQL subscripts using the `sql_subscript` method on most Sequel-specific expression objects:

    Sequel.expr(:column).sql_subscript(3) # column[3]
    Sequel.expr(:column).qualify(:table).sql_subscript(3) # table.column[3]

You can also use the `Sequel.subscript` method:

    Sequel.subscript(:column, 3) # column[3]

Just like in SQL, you can use any expression as a subscript:

    Sequel.subscript(:column, Sequel.function(:func)) # column[func()]

## Building Queries in Sequel

In Sequel, the SQL queries are build with method chaining.

### Creating Datasets

You generally start by creating a dataset by calling `Dataset#[]` with a symbol specifying the table name:

    DB[:albums] # SELECT * FROM albums

If you want to select from multiple FROM tables, use multiple arguments:

    DB[:albums, :artists] # SELECT * FROM albums, artists

If you don't want to select from any FROM tables, just call dataset:

    DB.dataset # SELECT *

### Chaining Methods

Once you have your dataset object, you build queries by chaining methods, usually with one method per clause in the query:

    DB[:albums].select(:id, :name).where(Sequel.like(:name, 'A%')).order(:name)
    # SELECT id, name FROM albums WHERE (name LIKE 'A%') ORDER BY name

Note that the order of your method chain is not usually important unless you have multiple methods that affect the same clause:

    DB[:albums].order(:name).where(Sequel.like(:name, 'A%')).select(:id, :name)
    # SELECT id, name FROM albums WHERE (name LIKE 'A%') ORDER BY name

### Using the Same Dataset for SELECT, INSERT, UPDATE, and DELETE

Also note that while the SELECT clause is displayed when you look at a dataset, a Sequel dataset can be used for INSERT, UPDATE, and DELETE as well. Here's an example:

    ds = DB[:albums]
    ds.all # SELECT * FROM albums
    ds.insert(:name=>'RF') # INSERT INTO albums (name) VALUES ('RF')
    ds.update(:name=>'RF') # UPDATE albums SET name = 'RF'
    ds.delete # DELETE FROM albums

In general, the `insert`, `update`, and `delete` methods use the appropriate clauses you defined on the dataset:

    ds = DB[:albums].where(:id=>1)
    ds.all # SELECT * FROM albums WHERE (id = 1)
    ds.insert(:name=>'RF') # INSERT INTO albums (name) VALUES ('RF')
    ds.update(:name=>'RF') # UPDATE albums SET name = 'RF' WHERE (id = 1)
    ds.delete # DELETE FROM albums WHERE (id = 1)

Note how `update` and `delete` used the `where` argument, but that `insert` did not, because INSERT doesn't use a WHERE clause.

### Methods Used for Each SQL Clause

To see which methods exist that affect each SQL clause, see the "Dataset Basics" guide.

[Validate]

Generated with the Darkfish Rdoc Generator 2.