August 7, 2023
Summary: The PostgreSQL ABS() function returns the absolute value of a number.
Table of Contents
Syntax
The following illustrates the syntax of the ABS() function:
ABS(numeric_expression)
Arguments
The ABS() function requires one argument:
1) numeric_expression
The numeric_expression can be a number or a numeric expression that evaluates to a number.
Return Value
The ABS() function returns a value whose data type is the same as the input argument.
Examples
The following example shows how to use the ABS() function to calculate the absolute value of a number:
SELECT ABS(-10.25)
The result is:
10.25
The following statement uses an expression for the ABS() function:
SELECT ABS( 100 - 250 );
Here is the result:
150
Besides the ABS() function, you can use the absolute operator @, for example:
SELECT @ -15
It returned 15 as expected.
15
In this tutorial, you have learned how to use the PostgreSQL ABS() function to calculate the absolute value of a number.
See more
PostgreSQL Tutorial: Math Functions
PostgreSQL Documentation: Mathematical Functions and Operators