Newer Version Available

This content describes an older version of this product. View Latest

Math Functions

To perform numeric operations in a SAQL query, use math functions.

You can use SAQL math functions in foreach statements and in the filter by clause after a foreach statement.

You can’t use SAQL math functions in group by or order by clauses, or in the filter by clause before a foreach statement.

Functions

This table lists the SAQL math functions:
Function Description
ABS(n) Returns the absolute number of n as a numeric value. n can be any real numeric value in the range of -1e308 <= n <= 1e308.
These examples are valid:
1abs(-1.2345) = 1.2345
2
3q = foreach q generate abs(pct_change) as pct_magnitude;
These examples are invalid:
1q = group q by abs(pct_change);
2q = order q by abs(pct_change);
CEIL(n) Returns the nearest integer of equal or greater value to n. n can be any real numeric value in the range of -1e308 <= n <= 1e308.
These examples are valid:
1ceil(-1.2345) = -1
2ceil(1.2345) = 2
3
4q = foreach q generate ceil(miles) as distance;
These examples are invalid:
1q = group q by ceil(miles);
2q = order q by ceil(miles);
FLOOR(n) Returns the nearest integer of equal or lesser value to n. n can be any real numeric value in the range of -1e308 <= n <= 1e308.
These examples are valid:
1floor(-1.2345) = -2
2floor(1.2345) = 1
3
4q = foreach q generate floor(miles) as distance;
These examples are invalid:
1q = group q by floor(miles);
2q = order q by floor(miles);
TRUNC(n[, m]) Returns the value of the numeric expression n truncated to m decimal places. m can be negative, in which case the function returns n truncated to -m places to the left of the decimal point. If m is omitted, it returns n truncated to the integer place. n can be any real numeric value in the range of -1e308 <= n <= 1e308. m can be an integer value between -15 and 15 inclusive.
These examples are valid:
1trunc(-1.2345) = -1
2trunc(1.2345) = 1
3trunc(2.355, 2) = 2.35
4trunc(-3455.8, -1) = -3450
5
6q = foreach q generate trunc(Price, 2) as Price;
These examples are invalid:
1trunc(1.2345, 2.5)
2trunc(1.2345, 1000)
3
4q = group q by trunc(Price, 2);
5q = order q by trunc(Price, 2);
ROUND(n[, m]) Returns the value of n rounded to m decimal places. m can be negative, in which case the function returns n rounded to -m places to the left of the decimal point. If m is omitted, it returns n rounded to the nearest integer. For tie-breaking, it follows round half way from zero convention. n can be any real numeric value in the range of -1e308 <= n <= 1e308. m can be an integer value between -15 and 15, inclusive.
These examples are valid:
1round(-1.2345) = -1
2round(2.355, 2) = 2.36
3round(-3455.8, -1) = -3460
4
5q = foreach q generate round(Price, 2) as Price;
These examples are invalid:
1round(1.2345, 2.5)
2round(1.2345, 1000)
3
4q = group q by round(Price, 2);
5q = order q by round(Price, 2);