abs
On this page
Returns the absolute value of a number.
Syntax
abs(<expr>)Arguments
| Argument | Type | Description |
|---|---|---|
<expr> | int, uint, or float | Input value. |
Returns
Returns the same type as the input. Returns NULL in either case:
- The input is NULL.
- The input is the minimum
int, -9223372036854775808. Its absolute value is outside theintrange.
Examples
Compare the magnitude of positive and negative inventory corrections without losing the signed adjustment.
VALUES ('evt-17', -12), ('evt-42', 5), ('evt-63', -2)
SELECT $0 AS event_id, $1 AS stock_delta
SELECT event_id, stock_delta, abs(stock_delta) AS changed_units
ORDER BY changed_units DESC+----------+-------------+---------------+
| event_id | stock_delta | changed_units |
+----------+-------------+---------------+
| evt-17 | -12 | 12 |
| evt-42 | 5 | 5 |
| evt-63 | -2 | 2 |
+----------+-------------+---------------+