Class | Sequel::Postgres::ArrayOp |
In: |
lib/sequel/extensions/pg_array_ops.rb
|
Parent: | Sequel::SQL::Wrapper |
CONCAT | = | ["(".freeze, " || ".freeze, ")".freeze].freeze |
CONTAINS | = | ["(".freeze, " @> ".freeze, ")".freeze].freeze |
CONTAINED_BY | = | ["(".freeze, " <@ ".freeze, ")".freeze].freeze |
OVERLAPS | = | ["(".freeze, " && ".freeze, ")".freeze].freeze |
Access a member of the array, returns an SQL::Subscript instance:
array_op[1] # array[1]
# File lib/sequel/extensions/pg_array_ops.rb, line 78 78: def [](key) 79: s = Sequel::SQL::Subscript.new(self, [key]) 80: s = ArrayOp.new(s) if key.is_a?(Range) 81: s 82: end
Call the ALL function:
array_op.all # ALL(array)
Usually used like:
dataset.where(1=>array_op.all) # WHERE (1 = ALL(array))
# File lib/sequel/extensions/pg_array_ops.rb, line 92 92: def all 93: function(:ALL) 94: end
Call the ANY function:
array_op.all # ANY(array)
Usually used like:
dataset.where(1=>array_op.any) # WHERE (1 = ANY(array))
# File lib/sequel/extensions/pg_array_ops.rb, line 104 104: def any 105: function(:ANY) 106: end
Use the contained by (<@) operator:
array_op.contained_by(:a) # (array <@ a)
# File lib/sequel/extensions/pg_array_ops.rb, line 118 118: def contained_by(other) 119: bool_op(CONTAINED_BY, wrap_array(other)) 120: end
Call the array_dims method:
array_op.dims # array_dims(array)
# File lib/sequel/extensions/pg_array_ops.rb, line 125 125: def dims 126: function(:array_dims) 127: end
Convert the array into an hstore using the hstore function. If given an argument, use the two array form:
array_op.hstore # hstore(array) array_op.hstore(:array2) # hstore(array, array2)
# File lib/sequel/extensions/pg_array_ops.rb, line 134 134: def hstore(arg=(no_arg_given=true; nil)) 135: v = if no_arg_given 136: Sequel.function(:hstore, self) 137: else 138: Sequel.function(:hstore, self, wrap_array(arg)) 139: end 140: if Sequel.respond_to?(:hstore_op) 141: v = Sequel.hstore_op(v) 142: end 143: v 144: end
Call the array_length method:
array_op.length # array_length(array, 1) array_op.length(2) # array_length(array, 2)
# File lib/sequel/extensions/pg_array_ops.rb, line 150 150: def length(dimension = 1) 151: function(:array_length, dimension) 152: end
Call the array_lower method:
array_op.lower # array_lower(array, 1) array_op.lower(2) # array_lower(array, 2)
# File lib/sequel/extensions/pg_array_ops.rb, line 158 158: def lower(dimension = 1) 159: function(:array_lower, dimension) 160: end
Return the receiver.
# File lib/sequel/extensions/pg_array_ops.rb, line 179 179: def pg_array 180: self 181: end
Use the concatentation (||) operator:
array_op.push(:a) # (array || a) array_op.concat(:a) # (array || a)
# File lib/sequel/extensions/pg_array_ops.rb, line 173 173: def push(other) 174: array_op(CONCAT, [self, wrap_array(other)]) 175: end
Remove the given element from the array:
array_op.remove(1) # array_remove(array, 1)
# File lib/sequel/extensions/pg_array_ops.rb, line 186 186: def remove(element) 187: ArrayOp.new(function(:array_remove, element)) 188: end
Replace the given element in the array with another element:
array_op.replace(1, 2) # array_replace(array, 1, 2)
# File lib/sequel/extensions/pg_array_ops.rb, line 194 194: def replace(element, replacement) 195: ArrayOp.new(function(:array_replace, element, replacement)) 196: 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, ':', '*')
# File lib/sequel/extensions/pg_array_ops.rb, line 204 204: def to_string(joiner="", null=nil) 205: function(:array_to_string, joiner, null) 206: end