ABS
Returns the absolute value of a number.
PostgreSQL 17.9
ABS(num)- num
- Numbernumeric | double precision
Return value
A non-negative number of the same type
Examples
Absolute value of a negative number
PostgreSQL 17.9
SELECT ABS(-5.7);Years away from 1980
PostgreSQL 17.9
SELECT member_name,
ABS(
EXTRACT(
YEAR
FROM birthday
) - 1980
) AS years_from_1980
FROM FamilyMembers;Details
The distance between two numbers, regardless of which one is larger, is ABS(a - b).