Appearance
ABS
Return the absolute value of a number.
ABS(number)
Alternatively, you can use @ number
(no parentheses around the number).
For example:
premdb=# SELECT ABS(-5);
abs
-----
5
(1 row)
premdb=# SELECT @ -5;
?column?
----------
5
(1 row)
The following example returns the absolute value for the result of an expression. The result represents the difference between the two numbers in the ftscore
column.
premdb=# SELECT ftscore,
ABS((SUBSTR(ftscore,1,1)::INT)-(SUBSTR(ftscore,3,1)::INT))
FROM match LIMIT 25;
ftscore | abs
---------+-----
0-1 | 1
0-1 | 1
2-1 | 1
3-0 | 3
3-0 | 3
2-0 | 2
0-0 | 0
0-0 | 0
0-1 | 1
1-0 | 1
0-1 | 1
...
Parent topic:Mathematical Functions