Riak TS Arithmetic Operations
Riak TS supports arithmetic operations in the SELECT
list.
Arithmetic operations default to 64-bit integer math, unless mixed with a
double
, at which point they become floating-point.
Important: Proper spacing around arithmetic operators is required.
Numeric Literals
Integer, decimal floating point, and exponent notation floating point numeric literals are accepted:
SELECT 555, 1.1, 1e1, 1.123e-2 from GeoCheckin
WHERE time > 1452252523182 AND time < 1452252543182 AND myfamily = 'family1' AND myseries = 'series1'
555<SINT64> | 1.1<DOUBLE> | 10.0<DOUBLE> | 0.01123<DOUBLE> |
---|---|---|---|
555 | 1.1 | 10.0 | 0.01123 |
Addition and Subtraction
SELECT temperature, temperature + 1, temperature - 1 FROM GeoCheckin
WHERE time > 1452252523182 AND time < 1452252543182 AND myfamily = 'family1' AND myseries = 'series1'
temperature<DOUBLE> | (temperature+1)<DOUBLE> | (temperature-1)<DOUBLE> |
---|---|---|
27.1 | 28.1 | 26.1 |
Multiplication and Division
SELECT temperature, temperature * 2, temperature / 2 from GeoCheckin
WHERE time > 1452252523182 AND time < 1452252543182 AND myfamily = 'family1' AND myseries = 'series1'
temperature<DOUBLE> | (temperature*2)<DOUBLE> | (temperature/2)<DOUBLE> |
---|---|---|
27.1 | 54.2 | 13.55 |
Negation
SELECT temperature, -temperature from GeoCheckin
WHERE time > 1452252523182 AND time < 1452252543182 AND myfamily = 'family1' AND myseries = 'series1'
temperature<DOUBLE> | -temperature<DOUBLE> |
---|---|
27.1 | -27.1 |
Order of Operations
SELECT temperature + 2 * 3, (temperature + 2) * 3 from GeoCheckin
WHERE time > 1452252523182 AND time < 1452252543182 AND myfamily = 'family1' AND myseries = 'series1'
(temperature+(2*3))<DOUBLE> | ((temperature+2)*3)<DOUBLE> |
---|---|
33.1 | 87.30000000000001 |
Floating Point Odds and Ends
Operations on floating point numbers that would return Infinity
or NaN
are
not supported.
For example, neither of these queries return successfully:
SELECT 0.0 / 0.0 from GeoCheckin
WHERE time > 1452252523182 AND time < 1452252543182 AND myfamily = 'family1' AND myseries = 'series1'
SELECT 1.0 / 0.0 from GeoCheckin
WHERE time > 1452252523182 AND time < 1452252543182 AND myfamily = 'family1' AND myseries = 'series1'
Operations with Multiple Field References
Operations involving two or more references to fields/columns are not supported.
This query will return an error:
SELECT temperature + temperature FROM GeoCheckin
WHERE time > 1452252523182 AND time < 1452252543182 AND myfamily = 'family1' AND myseries = 'series1'