Class: Sequel::SQL::StringAgg
- Inherits:
-
GenericExpression
- Object
- Expression
- GenericExpression
- Sequel::SQL::StringAgg
- Includes:
- AliasMethods, CastMethods, InequalityMethods, OrderMethods, PatternMatchMethods, StringConcatenationMethods, StringMethods, SubscriptMethods
- Defined in:
- lib/sequel/extensions/string_agg.rb
Overview
The StringAgg class represents an aggregate string concatentation.
Defined Under Namespace
Modules: DatasetMethods
Instance Attribute Summary collapse
-
#expr ⇒ Object
readonly
The string expression for each row that will concatenated to the output.
-
#order_expr ⇒ Object
readonly
The expression that the aggregation is ordered by.
-
#separator ⇒ Object
readonly
The separator between each string expression.
Instance Method Summary collapse
-
#distinct ⇒ Object
Return a modified StringAgg that uses distinct expressions.
-
#initialize(expr, separator = nil) {|_self| ... } ⇒ StringAgg
constructor
Set the expression and separator.
-
#is_distinct? ⇒ Boolean
Whether the current expression uses distinct expressions.
-
#order(*o) ⇒ Object
Return a modified StringAgg with the given order.
Methods included from SubscriptMethods
Methods included from PatternMatchMethods
Methods included from OrderMethods
Methods included from CastMethods
#cast, #cast_numeric, #cast_string
Methods included from AliasMethods
Methods included from StringConcatenationMethods
Methods included from StringMethods
#escaped_ilike, #escaped_like, #ilike, #like
Methods included from IsDistinctFrom::Methods
Methods included from Sequel::SQLite::JSONOpMethods
#sqlite_json_op, #sqlite_jsonb_op
Methods included from Postgres::HStoreOpMethods
Methods included from Postgres::RangeOpMethods
Methods included from Postgres::ArrayOpMethods
Methods included from Postgres::JSONOpMethods
Methods included from Postgres::InetOpMethods
Methods included from Postgres::PGRowOp::ExpressionMethods
Methods included from NumericMethods
Methods included from ComplexExpressionMethods
#extract, #sql_boolean, #sql_number, #sql_string
Methods included from BooleanMethods
Methods inherited from Expression
#==, attr_reader, #clone, #eql?, #hash, inherited, #inspect
Constructor Details
#initialize(expr, separator = nil) {|_self| ... } ⇒ StringAgg
Set the expression and separator
161 162 163 164 165 166 |
# File 'lib/sequel/extensions/string_agg.rb', line 161 def initialize(expr, separator=nil) @expr = expr @separator = separator yield self if defined?(yield) freeze end |
Instance Attribute Details
#expr ⇒ Object (readonly)
The string expression for each row that will concatenated to the output.
152 153 154 |
# File 'lib/sequel/extensions/string_agg.rb', line 152 def expr @expr end |
#order_expr ⇒ Object (readonly)
The expression that the aggregation is ordered by.
158 159 160 |
# File 'lib/sequel/extensions/string_agg.rb', line 158 def order_expr @order_expr end |
#separator ⇒ Object (readonly)
The separator between each string expression.
155 156 157 |
# File 'lib/sequel/extensions/string_agg.rb', line 155 def separator @separator end |
Instance Method Details
#distinct ⇒ Object
Return a modified StringAgg that uses distinct expressions
174 175 176 177 178 179 |
# File 'lib/sequel/extensions/string_agg.rb', line 174 def distinct self.class.new(@expr, @separator) do |sa| sa.instance_variable_set(:@order_expr, @order_expr) if @order_expr sa.instance_variable_set(:@distinct, true) end end |
#is_distinct? ⇒ Boolean
Whether the current expression uses distinct expressions
169 170 171 |
# File 'lib/sequel/extensions/string_agg.rb', line 169 def is_distinct? @distinct == true end |
#order(*o) ⇒ Object
Return a modified StringAgg with the given order
182 183 184 185 186 187 |
# File 'lib/sequel/extensions/string_agg.rb', line 182 def order(*o) self.class.new(@expr, @separator) do |sa| sa.instance_variable_set(:@distinct, @distinct) if @distinct sa.instance_variable_set(:@order_expr, o.empty? ? nil : o.freeze) end end |