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 461 def initialize(array, type=nil) 462 super(array) 463 @array_type = type 464 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 484 def sequel_auto_param_type(ds) 485 if array_type && all?{|x| nil == x || ds.send(:auto_param_type, x)} 486 "::#{array_type}[]" 487 end 488 end
Allow automatic parameterization of the receiver if all elements can be can be automatically parameterized.
Source
# File lib/sequel/extensions/pg_array.rb 469 def sql_literal_append(ds, sql) 470 at = array_type 471 if empty? && at 472 sql << "'{}'" 473 else 474 sql << "ARRAY" 475 _literal_append(sql, ds, to_a) 476 end 477 if at 478 sql << '::' << at.to_s << '[]' 479 end 480 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 495 def _literal_append(sql, ds, array) 496 sql << '[' 497 comma = false 498 commas = ',' 499 array.each do |i| 500 sql << commas if comma 501 if i.is_a?(Array) 502 _literal_append(sql, ds, i) 503 else 504 ds.literal_append(sql, i) 505 end 506 comma = true 507 end 508 sql << ']' 509 end
Recursive method that handles multi-dimensional arrays, surrounding each with [] and interspersing entries with ,.