negative function

Returns the negated value of expr.

Syntax

negative(expr)

Arguments

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

Returns

The result type matches the argument type.

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

This function is a synonym for - (minus sign) unary operator.

Warning

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

Examples

> SELECT negative(1);
 -1

> SELECT negative(cast(-32768 AS smallint))
 Error: ARITHMETIC_OVERFLOW