Module Sequel::SQL::NumericMethods
In: lib/sequel/sql.rb

This module includes the standard mathematical methods (+, -, *, and /) that are defined on objects that can be used in a numeric context in SQL (Symbol, LiteralString, and +SQL::GenericExpression+).

  :a + :b # "a" + "b"
  :a - :b # "a" - "b"
  :a * :b # "a" * "b"
  :a / :b # "a" / "b"

One exception to this is if + is called with a String or StringExpression, in which case the || operator is used instead of the + operator:

  :a + 'b' # "a" || 'b'

Methods

+   coerce  

Public Instance methods

Use || as the operator when called with StringExpression and String instances, and the + operator for LiteralStrings and all other types.

[Source]

     # File lib/sequel/sql.rb, line 813
813:       def +(ce)
814:         case ce
815:         when LiteralString
816:           NumericExpression.new(:+, self, ce)
817:         when StringExpression, String
818:           StringExpression.new('||''||', self, ce)
819:         else
820:           NumericExpression.new(:+, self, ce)
821:         end
822:       end

If the argument given is Numeric, treat it as a NumericExpression, allowing code such as:

  1 + Sequel[:x] # SQL: (1 + x)
  Sequel.expr{1 - x(y)} # SQL: (1 - x(y))

[Source]

     # File lib/sequel/sql.rb, line 803
803:       def coerce(other)
804:         if other.is_a?(Numeric)
805:           [SQL::NumericExpression.new(:NOOP, other), self]
806:         else
807:           super 
808:         end
809:       end

[Validate]