ABS

Return the absolute value of a numeric expression.

Category: mathReturns: NUMERICDialect: Standard

Syntax

ABS(expr)

Description

## Overview Returns the absolute value (magnitude without sign) of the numeric input. ABS is the most common primitive for converting a signed quantity into a magnitude: distances, amounts, error measurements, and absolute deviations all go through ABS. ABS preserves the input type: ABS of an INTEGER is an INTEGER, ABS of a DECIMAL(10, 2) is a DECIMAL(10, 2), ABS of a DOUBLE is a DOUBLE. This type preservation makes ABS a cheap, non-coercing operator that rarely introduces type surprises downstream. ## Behavior - Accepts any numeric type (INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL). - Returns a value of the same type as the input. - Returns NULL if the argument is NULL. - ABS(0) is 0, not -0. Negative zero in floating-point is canonicalized to positive zero. - ABS of the minimum representable signed integer (for example, BIGINT -9223372036854775808) overflows because the positive counterpart is not representable. Engines typically raise an error in that case. ## Numeric precision - For INTEGER and BIGINT, ABS is exact except at the signed minimum value. - For DOUBLE, ABS flips only the sign bit and introduces no rounding. - For DECIMAL, ABS preserves the declared scale and precision. ## Compatibility - Conforms to the SQL standard scalar function ABS. - Matches typical mathematical library implementations.

Parameters

NameTypeDescription
exprSpecifies the numeric expression to evaluate. Accepts any numeric type including INTEGER, BIGINT, DOUBLE, FLOAT, and DECIMAL. The return type matches the input type.

Examples

-- Basic literal: absolute value of a negative integer
SELECT ABS(-42);
-- Result: 42
-- Positive value is unchanged
SELECT ABS(17);
-- Result: 17
-- ABS of zero
SELECT ABS(0);
-- Result: 0
-- Floating-point input preserves DOUBLE type
SELECT ABS(-3.14159);
-- Result: 3.14159
-- NULL propagation
SELECT ABS(NULL);
-- Result: NULL
-- Column use: magnitude of price change per trade
SELECT trade_id, ABS(close_price - open_price) AS intra_day_move
FROM finance.trades.orders;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →