class Sequel::Postgres::PGArray
Represents a PostgreSQL array column value.
:nocov:
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 439 def initialize(array, type=nil) 440 super(array) 441 @array_type = type 442 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 447 def sql_literal_append(ds, sql) 448 at = array_type 449 if empty? && at 450 sql << "'{}'" 451 else 452 sql << "ARRAY" 453 _literal_append(sql, ds, to_a) 454 end 455 if at 456 sql << '::' << at.to_s << '[]' 457 end 458 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 465 def _literal_append(sql, ds, array) 466 sql << '[' 467 comma = false 468 commas = ',' 469 array.each do |i| 470 sql << commas if comma 471 if i.is_a?(Array) 472 _literal_append(sql, ds, i) 473 else 474 ds.literal_append(sql, i) 475 end 476 comma = true 477 end 478 sql << ']' 479 end