Return the arithmetic negation of a numeric expression.
NEGATIVE(expr)
## Overview Returns the arithmetic negation of the input: equivalent to multiplying by -1. NEGATIVE exists as a function form of the unary minus operator, which can be convenient in contexts (such as framework-generated SQL or expression trees) where operators are awkward to emit. For most human-written SQL, the unary minus operator (-expr) is shorter and equally correct. ## Behavior - Accepts any numeric type. - Returns a value of the same type as the input. - Returns NULL if the argument is NULL. - NEGATIVE(0) is 0, not -0. - NEGATIVE of the minimum signed integer overflows (the positive counterpart is not representable in the same type). ## Numeric precision - For DECIMAL and integer types, negation is exact except at the signed minimum. - For DOUBLE, negation flips only the sign bit and introduces no rounding. ## Compatibility - Conforms to the SQL standard convention that unary minus and NEGATIVE are equivalent. - Matches typical mathematical library implementations.
| Name | Type | Description |
|---|---|---|
expr | Specifies the numeric expression to negate. Accepts any numeric type. The return type matches the input type. |
-- Negate a positive
SELECT NEGATIVE(42);
-- Result: -42
-- Negate a negative
SELECT NEGATIVE(-7);
-- Result: 7
-- Negate zero
SELECT NEGATIVE(0);
-- Result: 0
-- Negate a DOUBLE
SELECT NEGATIVE(3.14);
-- Result: -3.14
-- Same as unary minus
SELECT NEGATIVE(5), -5;
-- Result: -5, -5
-- Column use: flip the sign of a debit to treat as a credit
SELECT txn_id, NEGATIVE(debit_amount) AS credit_amount
FROM finance.ledger.transactions;