Skip to main content

ABS function

Returns the absolute (positive) value of a numeric expression.

Syntax

ABS(expression)

Arguments

  • expression: A numeric expression (INTEGER, BIGINT, DECIMAL, or DOUBLE).

Returns

The absolute value of the input expression. The return type matches the input type.

Special Values

  • ABS(inf) returns inf

  • ABS(-inf) returns inf

  • ABS(NaN) returns NaN

  • ABS(NULL) returns NULL

  • ABS(-0.0) returns 0.0

Examples

-- Example 1: Basic absolute values
> SELECT ABS(7), ABS(-77.5), ABS(0), ABS(-0.0);
7, 77.5, 0, 0.0

-- Example 2: Special floating-point values
> SELECT ABS(CAST('inf' AS DOUBLE)), ABS(CAST('-inf' AS DOUBLE));
inf, inf

> SELECT ABS(CAST('NaN' AS DOUBLE));
NaN

-- Example 3: NULL handling
> SELECT ABS(CAST(NULL AS DOUBLE));
NULL