abs function

Returns the absolute value of the numeric value in expr.

Syntax

abs(expr)

Arguments

  • expr: An expression that evaluates to a numeric or interval.

Interval is supported Since: Databricks Runtime 10.1

Returns

A numeric or interval of the same type as expr.

For integral numeric types the function can return an ARITHMETIC_OVERFLOW error.

Warning

If spark.sql.ansi.enabled is false an overflow will not cause an error but “wrap” the result.

Examples

> SELECT abs(-1);
 1

> SELECT abs(cast(-32768 AS Smallint))
 Error: ARITHMETIC_OVERFLOW