PostgreSQL abs() Function

The PostgreSQL abs() function returns the absolute value of the specified number.

abs() Syntax

This is the syntax of the PostgreSQL abs() function:

abs(numeric_value) -> numeric type

Parameters

numeric_value

Required. A number, it can be positive, negative, or zero. It can be an integer or a decimal.

Return value

The PostgreSQL abs() function returns the absolute value of the specified parameter.

The abs() function will return NULL if the parameter is NULL.

PostgreSQL will give an error if you supply a parameter that is not a numeric type.

abs() Examples

Here are a few examples of the abs() function:

SELECT
    abs(0) AS "abs(0)",
    abs(7) AS "abs(7)",
    abs(-7) AS "abs(-7)",
    abs(1.2) AS "abs(1.2)",
    abs(-1.2) AS "abs(-1.2)";
 abs(0) | abs(7) | abs(-7) | abs(1.2) | abs(-1.2)
--------+--------+---------+----------+-----------
      0 |      7 |       7 |      1.2 |       1.2