class Sequel::Postgres::PGArray
Represents a PostgreSQL array column value.
Attributes
array_type[RW]
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
new(array, type=nil)
click to toggle source
Set the array to delegate to, and a database type.
Calls superclass method
# File lib/sequel/extensions/pg_array.rb 434 def initialize(array, type=nil) 435 super(array) 436 @array_type = type 437 end
Public Instance Methods
op()
click to toggle source
sql_literal_append(ds, sql)
click to toggle source
Append the array SQL
to the given sql string. If the receiver has a type, add a cast to the database array type.
# File lib/sequel/extensions/pg_array.rb 442 def sql_literal_append(ds, sql) 443 at = array_type 444 if empty? && at 445 sql << "'{}'" 446 else 447 sql << "ARRAY" 448 _literal_append(sql, ds, to_a) 449 end 450 if at 451 sql << '::' << at.to_s << '[]' 452 end 453 end
Private Instance Methods
_literal_append(sql, ds, array)
click to toggle source
Recursive method that handles multi-dimensional arrays, surrounding each with [] and interspersing entries with ,.
# File lib/sequel/extensions/pg_array.rb 460 def _literal_append(sql, ds, array) 461 sql << '[' 462 comma = false 463 commas = ',' 464 array.each do |i| 465 sql << commas if comma 466 if i.is_a?(Array) 467 _literal_append(sql, ds, i) 468 else 469 ds.literal_append(sql, i) 470 end 471 comma = true 472 end 473 sql << ']' 474 end