abs(numeric) — Absolute value of a number
Last updated: 2026-11-04
abs(numeric) — Absolute value of a number
abs() returns the absolute value of a number, turning negatives positive and leaving everything else untouched. It is essential for deviation statistics, differences and distances, and it removes the influence of sign on aggregates.
| Kind | function |
|---|---|
| Example Language | SQL |
📝 Syntax
abs(value numeric) → numeric
⚙️ Parameters
| value numeric | The number to take the absolute value of. Type numeric; integer, double precision and other numeric types are also accepted. |
|---|
Returns:numeric — the absolute value; the result keeps the input type.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | label | value | abs_value
----+-------+--------+-----------
1 | high | 273.45 | 273.45
2 | low | -19.99 | 19.99
3 | zero | 0.00 | 0.00
(3 rows)
📌 Key Points
- The result type follows the input: abs(numeric) returns numeric and abs(integer) returns integer.
- There is no minimum-value overflow with numeric, but taking the absolute value of the smallest bigint raises an error.
- Be careful to distinguish avg(abs(x)) from abs(sum(x) / count(*)) — they measure very different things.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QHow is abs() different from sign()?
Aabs() returns the number with its sign removed, while sign() returns only the direction (-1, 0 or 1). Use sign() to count up and down moves and abs() to measure how large the moves are.