sum()
Calculates the sum of numeric values returned by an expression.
Syntax
Parameters
NUM_EXPR- An expression that returns the numeric values to sum.
Description
The sum() function evaluates NUM_EXPR for each record and accumulates the numeric sum. It tracks integers (long) and floating-point numbers (double) separately. If only integer values are present, it returns a 64-bit integer. If any floating-point values are present, it adds the integer sum and the floating-point sum and returns the result. Null values and non-numeric values are excluded from aggregation. If all input values are null or non-numeric, it returns null.
Use this function in aggregation commands such as stats and timechart.
Error codes
| Code | Description |
|---|---|
| 91020 | The number of arguments is incorrect. |
Usage examples
To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.
-
Calculate the total response size across all requests
table WEB_APACHE_SAMPLE | stats sum(bytes) -
Calculate the total response size per HTTP method
table WEB_APACHE_SAMPLE | stats sum(bytes) by method -
Null value handling
json "[{'val': 10}, {'val': null}, {'val': 30}]" | stats sum(val) | # sum(val): 40
Compatibility
The sum() function has been available since before Logpresso Sonar 4.0.