class Sequel::Postgres::PGArray
Represents a PostgreSQL array column value.
simplecov:enable
Attributes
The type of this array. May be nil if no type was given. If a type is provided, the array is automatically casted to this type when literalizing. This type is the underlying type, not the array type itself, so for an int4[] database type, it should be :int4 or βint4β
Public Class Methods
Source
# File lib/sequel/extensions/pg_array.rb 462 def initialize(array, type=nil) 463 super(array) 464 @array_type = type 465 end
Set the array to delegate to, and a database type.
Calls superclass method
Public Instance Methods
Source
# File lib/sequel/extensions/pg_array_ops.rb 390 def op 391 ArrayOp.new(self) 392 end
Source
# File lib/sequel/extensions/pg_array.rb 485 def sequel_auto_param_type(ds) 486 if array_type && all?{|x| nil == x || ds.send(:auto_param_type, x)} 487 "::#{array_type}[]" 488 end 489 end
Allow automatic parameterization of the receiver if all elements can be can be automatically parameterized.
Source
# File lib/sequel/extensions/pg_array.rb 470 def sql_literal_append(ds, sql) 471 at = array_type 472 if empty? && at 473 sql << "'{}'" 474 else 475 sql << "ARRAY" 476 _literal_append(sql, ds, to_a) 477 end 478 if at 479 sql << '::' << at.to_s << '[]' 480 end 481 end
Append the array SQL to the given sql string. If the receiver has a type, add a cast to the database array type.
Private Instance Methods
Source
# File lib/sequel/extensions/pg_array.rb 496 def _literal_append(sql, ds, array) 497 sql << '[' 498 comma = false 499 commas = ',' 500 array.each do |i| 501 sql << commas if comma 502 if i.is_a?(Array) 503 _literal_append(sql, ds, i) 504 else 505 ds.literal_append(sql, i) 506 end 507 comma = true 508 end 509 sql << ']' 510 end
Recursive method that handles multi-dimensional arrays, surrounding each with [] and interspersing entries with ,.