Signature
abs ( numeric_type ) → numeric_typeParameters
| Parameter | Type | Description |
|---|---|---|
| x | numeric | Any numeric value |
Examples
SELECT abs(-17.4);17.4SELECT abs(17.4);17.4SELECT abs(-2147483648::bigint);2147483648SELECT id, amount FROM adjustments WHERE abs(amount) > 10000 ORDER BY abs(amount) DESC;Rows with large positive or negative adjustmentsSELECT avg(abs(actual - forecast)) AS mae FROM predictions;Mean absolute error of forecastsWriting `WHERE abs(delta) < 5` prevents PostgreSQL from using an index on `delta`. The planner cannot invert a function wrapper to perform an index seek.
✓ Instead: Rewrite as `WHERE delta BETWEEN -5 AND 5` to allow a btree index scan on `delta`.
Use `abs(a - b)` to compute unsigned distance between two values. This is common in tolerance checks: `WHERE abs(measured - expected) < 0.001` is cleaner than writing both `> -0.001 AND < 0.001`.
SELECT id FROM readings WHERE abs(value - target) > tolerance;Rows where deviation exceeds tolerance