| 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 91
91: def [](key)
92: s = Sequel::SQL::Subscript.new(self, [key])
93: s = ArrayOp.new(s) if key.is_a?(Range)
94: s
95: 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 105
105: def all
106: function(:ALL)
107: 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 117
117: def any
118: function(:ANY)
119: end
Call the cardinality method:
array_op.cardinality # cardinality(array)
# File lib/sequel/extensions/pg_array_ops.rb, line 124
124: def cardinality
125: function(:cardinality)
126: end
Use the contained by (<@) operator:
array_op.contained_by(:a) # (array <@ a)
# File lib/sequel/extensions/pg_array_ops.rb, line 138
138: def contained_by(other)
139: bool_op(CONTAINED_BY, wrap_array(other))
140: end
Call the array_dims method:
array_op.dims # array_dims(array)
# File lib/sequel/extensions/pg_array_ops.rb, line 145
145: def dims
146: function(:array_dims)
147: 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 154
154: def hstore(arg=(no_arg_given=true; nil))
155: v = if no_arg_given
156: Sequel.function(:hstore, self)
157: else
158: Sequel.function(:hstore, self, wrap_array(arg))
159: end
160: if Sequel.respond_to?(:hstore_op)
161: v = Sequel.hstore_op(v)
162: end
163: v
164: 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 170
170: def length(dimension = 1)
171: function(:array_length, dimension)
172: 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 178
178: def lower(dimension = 1)
179: function(:array_lower, dimension)
180: end
Return the receiver.
# File lib/sequel/extensions/pg_array_ops.rb, line 199
199: def pg_array
200: self
201: 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 193
193: def push(other)
194: array_op(CONCAT, [self, wrap_array(other)])
195: 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 206
206: def remove(element)
207: ArrayOp.new(function(:array_remove, element))
208: 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 214
214: def replace(element, replacement)
215: ArrayOp.new(function(:array_replace, element, replacement))
216: 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 224
224: def to_string(joiner="", null=nil)
225: function(:array_to_string, joiner, null)
226: end