class Sequel::Postgres::PGRowOp

This class represents a composite type expression reference.

Constants

CLOSE_DOT
CLOSE_STAR
CLOSE_STAR_CAST
EMPTY
OPEN
QUALIFY
ROW
ROW_CAST
WRAP

Public Class Methods

wrap(expr) click to toggle source

Wrap the expression in a PGRowOp, without changing the SQL it would use.

# File lib/sequel/extensions/pg_row_ops.rb, line 99
def self.wrap(expr)
  PGRowOp.new(WRAP, [expr])
end

Public Instance Methods

*(ce=(arg=false;nil)) click to toggle source

Use the (identifier).* syntax to reference the members of the composite type as separate columns. Generally used when you want to expand the columns of a composite type to be separate columns in the result set.

Sequel.pg_row_op(:a).*     # (a).*
Sequel.pg_row_op(:a)[:b].* # ((a).b).*
Calls superclass method
# File lib/sequel/extensions/pg_row_ops.rb, line 124
def *(ce=(arg=false;nil))
  if arg == false
    Sequel::SQL::ColumnAll.new([self])
  else
    super(ce)
  end
end
[](member) click to toggle source

Access a member of the composite type if given a symbol or an SQL::Identifier. For all other access, assuming the pg_array_ops extension is loaded and that it represents an array access. In either case, return a PgRowOp so that access can be cascaded.

# File lib/sequel/extensions/pg_row_ops.rb, line 108
def [](member)
  case member
  when Symbol, SQL::Identifier
    PGRowOp.new(QUALIFY, [self, member])
  else
    PGRowOp.wrap(Sequel.pg_array_op(self)[member])
  end
end
splat(cast_to=nil) click to toggle source

Use the (identifier.*) syntax to indicate that this expression represents the composite type of one of the tables being referenced, if it has the same name as one of the columns. If the cast_to argument is given, also cast the expression to that type (which should be a symbol representing the composite type). This is used if you want to return whole table row as a composite type.

Sequel.pg_row_op(:a).splat[:b] # (a.*).b
Sequel.pg_row_op(:a).splat(:a) # (a.*)::a
# File lib/sequel/extensions/pg_row_ops.rb, line 143
def splat(cast_to=nil)
  if args.length > 1
    raise Error, 'cannot splat a PGRowOp with multiple arguments'
  end

  if cast_to
    PGRowOp.new(ROW_CAST, args + [cast_to])
  else
    PGRowOp.new(ROW, args)
  end
end