class Sequel::Postgres::PGArray

Base class for the PostgreSQL array types. Subclasses generally just deal with parsing, so instances manually created from arrays can use this class correctly.

Constants

ARRAY
BACKSLASH
CLOSE_BRACE
CLOSE_BRACKET
COMMA
DOUBLE_COLON
EMPTY_BRACKET
EMPTY_STRING
NULL
OPEN_BRACE
OPEN_BRACKET
QUOTE

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.

# File lib/sequel/extensions/pg_array.rb, line 293
def initialize(array, type=nil)
  super(array)
  self.array_type = type
end
parse(string, type=nil) click to toggle source

Parse the string using the generalized parser, setting the type if given.

# File lib/sequel/extensions/pg_array.rb, line 276
def self.parse(string, type=nil)
  new(Parser.new(string, method(:convert_item)).parse, type)
end

Public Instance Methods

op() click to toggle source

Wrap the PGArray instance in an ArrayOp, allowing you to easily use the PostgreSQL array functions and operators with literal arrays.

# File lib/sequel/extensions/pg_array_ops.rb, line 202
def op
  ArrayOp.new(self)
end
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, line 304
def sql_literal_append(ds, sql)
  sql << ARRAY
  _literal_append(sql, ds, to_a)
  if at = array_type
    sql << DOUBLE_COLON << at.to_s << EMPTY_BRACKET
  end
end