Class: Sequel::Postgres::CreateTableGenerator

Inherits:
Schema::CreateTableGenerator
  • Object
show all
Defined in:
lib/sequel/adapters/shared/postgres.rb

Instance Method Summary collapse

Instance Method Details

#exclude(elements, opts = OPTS) ⇒ Object

Add an exclusion constraint when creating the table. Elements should be an array of 2 element arrays, with the first element being the column or expression the exclusion constraint is applied to, and the second element being the operator to use for the column/expression to check for exclusion:

exclude([[:col1, '&&'], [:col2, '=']])
# EXCLUDE USING gist (col1 WITH &&, col2 WITH =)

To use a custom operator class, you need to use Sequel.lit with the expression and operator class:

exclude([[Sequel.lit('col1 inet_ops'), '&&'], [:col2, '=']])
# EXCLUDE USING gist (col1 inet_ops WITH &&, col2 WITH =)

Options supported:

:include :: Include additional columns in the underlying index, to allow for index-only scans in more cases (PostgreSQL 11+). :name :: Name the constraint with the given name (useful if you may need to drop the constraint later) :using :: Override the index_method for the exclusion constraint (defaults to gist). :where :: Create a partial exclusion constraint, which only affects a subset of table rows, value should be a filter expression.



134
135
136
# File 'lib/sequel/adapters/shared/postgres.rb', line 134

def exclude(elements, opts=OPTS)
  constraints << {:type => :exclude, :elements => elements}.merge!(opts)
end

#like(table, excluding: nil, including: nil) ⇒ Object

Copies the column names, data types, and not null constraints from the specified table using LIKE. Arguments: table: Name of table to copy from excluding: LIKE options to exclude, can be a symbol or array of symbols (options: :comments, :compression:, :constraints, :defaults, :generated, :identity, :indexes, :statistics, :storage, :all) including: LIKE options to include (same values supported as excluding)



145
146
147
# File 'lib/sequel/adapters/shared/postgres.rb', line 145

def like(table, excluding: nil, including: nil)
  columns << {like_table: table, excluding: Array(excluding), including: Array(including)}
end