class ActiveRecord::ConnectionAdapters::PostgreSQLExcludeConstraint

Creates EXCLUDE constraints for PostgreSQL tables and columns.

This class is meant to be used by PostgreSQL column and table definition and manipulation methods. There are two ways to create a EXCLUDE constraint:

In both cases, a Hash or an Array of Hashes should be used to set the EXCLUDE constraint checks. The Hash(es) should be in the format { :element => ..., :with => ... }, where :element is a column name or expression and :with is the operator to compare against. The key :operator is an alias for :where.

Table Definition

EXCLUDE constraints can also be applied to the table directly rather than on a column definition.

Example

The following example produces the same result as above:

create_table('foo') do |t|
  t.integer :blort
  t.exclude({
    :element => 'length(blort)',
    :with => '='
  }, {
    :name => 'exclude_blort_length'
  })
end

# Produces:
#
# CREATE TABLE "foo" (
#   "id" serial primary key,
#   "blort" text,
#   CONSTRAINT "exclude_blort_length" EXCLUDE (length(blort) WITH =)
# );

Table Manipulation

You can also create new EXCLUDE constraints outside of a table definition using PostgreSQLAdapter#add_exclude_constraint.

Examples

add_exclude_constraint(:foo, { :element => :bar_id, :with => '=' })
# => ALTER TABLE "foo" ADD EXCLUDE ("bar_id" WITH =);

Options for EXCLUDE Constraints

Dropping EXCLUDE Constraints

Like all PostgreSQL constraints, you can use PostgreSQLAdapter#drop_constraint to remove a constraint from a table.

Attributes

excludes[RW]