Class: Sequel::SQL::StringAgg

Overview

The StringAgg class represents an aggregate string concatentation.

Defined Under Namespace

Modules: DatasetMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SubscriptMethods

#sql_subscript

Methods included from PatternMatchMethods

#=~

Methods included from OrderMethods

#asc, #desc

Methods included from CastMethods

#cast, #cast_numeric, #cast_string

Methods included from AliasMethods

#as

Methods included from StringConcatenationMethods

#+

Methods included from StringMethods

#ilike, #like

Methods included from Postgres::HStoreOpMethods

#hstore

Methods included from Postgres::RangeOpMethods

#pg_range

Methods included from Postgres::ArrayOpMethods

#pg_array

Methods included from Postgres::JSONOpMethods

#pg_json, #pg_jsonb

Methods included from Postgres::InetOpMethods

#pg_inet

Methods included from Postgres::PGRowOp::ExpressionMethods

#pg_row

Methods included from NumericMethods

#+, #coerce

Methods included from ComplexExpressionMethods

#extract, #sql_boolean, #sql_number, #sql_string

Methods included from BooleanMethods

#~

Methods inherited from Expression

#==, attr_reader, #eql?, #hash, inherited, #inspect, #lit, #sql_literal

Constructor Details

#initialize(expr, separator = nil) ⇒ StringAgg

Set the expression and separator



148
149
150
151
# File 'lib/sequel/extensions/string_agg.rb', line 148

def initialize(expr, separator=nil)
  @expr = expr
  @separator = separator
end

Instance Attribute Details

#exprObject (readonly)

The string expression for each row that will concatenated to the output.



139
140
141
# File 'lib/sequel/extensions/string_agg.rb', line 139

def expr
  @expr
end

#order_exprObject (readonly)

The expression that the aggregation is ordered by.



145
146
147
# File 'lib/sequel/extensions/string_agg.rb', line 145

def order_expr
  @order_expr
end

#separatorObject (readonly)

The separator between each string expression.



142
143
144
# File 'lib/sequel/extensions/string_agg.rb', line 142

def separator
  @separator
end

Instance Method Details

#distinctObject

Return a modified StringAgg that uses distinct expressions



159
160
161
162
163
# File 'lib/sequel/extensions/string_agg.rb', line 159

def distinct
  sa = dup
  sa.instance_variable_set(:@distinct, true)
  sa
end

#is_distinct?Boolean

Whether the current expression uses distinct expressions

Returns:

  • (Boolean)


154
155
156
# File 'lib/sequel/extensions/string_agg.rb', line 154

def is_distinct?
  @distinct == true
end

#order(*o) ⇒ Object

Return a modified StringAgg with the given order



166
167
168
169
170
# File 'lib/sequel/extensions/string_agg.rb', line 166

def order(*o)
  sa = dup
  sa.instance_variable_set(:@order_expr, o.empty? ? nil : o)
  sa
end