ABS
Returns the absolute (positive) value of a numeric expression
Syntax
ABS( expr )
Arguments
| Parameter | Description | 
|---|---|
| 
 | Numeric expression | 
Returns
Returns the same type as the argument supplied.
Notes
- If the value is NULL, the result is NULL. 
Examples
For these examples, consider the following table and contents:
CREATE TABLE cool_numbers(i INT, f DOUBLE);
INSERT INTO cool_numbers VALUES (1,1.618033), (-12, -34)
, (22, 3.141592), (-26538, 2.7182818284)
, (NULL, NULL), (NULL,1.4142135623)
, (42,NULL), (-42, NULL)
, (-474, 365);
Absolute value on an integer
numbers=> SELECT ABS(-24);
24
Absolute value on integer and floating point
numbers=> SELECT i, ABS(i), f, ABS(f) FROM cool_numbers;
i      | abs   | f    | abs0
-------+-------+------+-----
     1 |     1 | 1.62 | 1.62
   -12 |    12 |  -34 |   34
    22 |    22 | 3.14 | 3.14
-26538 | 26538 | 2.72 | 2.72
       |       |      |
       |       | 1.41 | 1.41
    42 |    42 |      |
   -42 |    42 |      |
  -474 |   474 |  365 |  365