PostgreSQL ABS() Function
The PostgreSQL ABS()
function returns the absolute value of a number.
Syntax
The following illustrates the syntax of the ABS()
function:
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.
Absolute Operator @
Besides the ABS() function, you can use the absolute operator @:
In this syntax, the @
operator returns the absolute value of the expression
.
Examples
The following example shows how to use the ABS()
function to calculate the absolute value of a number:
The result is:
The following statement uses an expression for the ABS()
function:
Here is the result:
Besides the ABS()
function, you can use the absolute operator @
, for example:
It returned 15 as expected.
In this tutorial, you have learned how to use the PostgreSQL ABS()
function to calculate the absolute value of a number.