Class Sequel::Postgres::ArrayOp
In: lib/sequel/extensions/pg_array_ops.rb
Parent: Sequel::SQL::Wrapper

The ArrayOp class is a simple container for a single object that defines methods that yield Sequel expression objects representing PostgreSQL array operators and functions.

In the method documentation examples, assume that:

  array_op = :array.pg_array

Methods

[]   all   any   concat   contained_by   contains   dims   join   length   lower   overlaps   pg_array   push   to_string   unnest   unshift  

Constants

CONCAT = ["(".freeze, " || ".freeze, ")".freeze].freeze
CONTAINS = ["(".freeze, " @> ".freeze, ")".freeze].freeze
CONTAINED_BY = ["(".freeze, " <@ ".freeze, ")".freeze].freeze
OVERLAPS = ["(".freeze, " && ".freeze, ")".freeze].freeze

Public Instance methods

Access a member of the array, returns an SQL::Subscript instance:

  array_op[1] # array[1]

[Source]

    # File lib/sequel/extensions/pg_array_ops.rb, line 77
77:       def [](key)
78:         Sequel::SQL::Subscript.new(self, [key])
79:       end

Call the ALL function:

  array_op.all # ALL(array)

Usually used like:

  dataset.where(1=>array_op.all)
  # WHERE (1 = ALL(array))

[Source]

    # File lib/sequel/extensions/pg_array_ops.rb, line 89
89:       def all
90:         function(:ALL)
91:       end

Call the ANY function:

  array_op.all # ANY(array)

Usually used like:

  dataset.where(1=>array_op.any)
  # WHERE (1 = ANY(array))

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 101
101:       def any
102:         function(:ANY)
103:       end
concat(other)

Alias for push

Use the contained by (<@) operator:

  array_op.contained_by(:a) # (array <@ a)

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 115
115:       def contained_by(other)
116:         bool_op(CONTAINED_BY, other)
117:       end

Use the contains (@>) operator:

  array_op.contains(:a) # (array @> a)

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 108
108:       def contains(other)
109:         bool_op(CONTAINS, other)
110:       end

Call the array_dims method:

  array_op.dims # array_dims(array)

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 122
122:       def dims
123:         function(:array_dims)
124:       end
join(joiner="", null=nil)

Alias for to_string

Call the array_length method:

  array_op.length    # array_length(array, 1)
  array_op.length(2) # array_length(array, 2)

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 130
130:       def length(dimension = 1)
131:         function(:array_length, dimension)
132:       end

Call the array_lower method:

  array_op.lower    # array_lower(array, 1)
  array_op.lower(2) # array_lower(array, 2)

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 138
138:       def lower(dimension = 1)
139:         function(:array_lower, dimension)
140:       end

Use the overlaps (&&) operator:

  array_op.overlaps(:a) # (array && a)

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 145
145:       def overlaps(other)
146:         bool_op(OVERLAPS, other)
147:       end

Return the receiver.

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 159
159:       def pg_array
160:         self
161:       end

Use the concatentation (||) operator:

  array_op.push(:a) # (array || a)
  array_op.concat(:a) # (array || a)

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 153
153:       def push(other)
154:         array_op(CONCAT, [self, other])
155:       end

Call the array_to_string method:

  array_op.join           # array_to_string(array, '', NULL)
  array_op.to_string      # array_to_string(array, '', NULL)
  array_op.join(":")      # array_to_string(array, ':', NULL)
  array_op.join(":", "*") # array_to_string(array, ':', '*')

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 169
169:       def to_string(joiner="", null=nil)
170:         function(:array_to_string, joiner, null)
171:       end

Call the unnest method:

  array_op.unnest # unnest(array)

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 177
177:       def unnest
178:         function(:unnest)
179:       end

Use the concatentation (||) operator, reversing the order:

  array_op.unshift(:a) # (a || array)

[Source]

     # File lib/sequel/extensions/pg_array_ops.rb, line 184
184:       def unshift(other)
185:         array_op(CONCAT, [other, self])
186:       end

[Validate]