Postgresql Abs Function

PostgreSQL: abs Function

In this PostgreSQL post explains how to use the PostgreSQL abs function with syntax and examples.

Description

The PostgreSQL abs function returns the absolute value of a number.

Syntax

The syntax for the abs function in PostgreSQL is:

abs( number )

Parameters or Arguments

number

The number to convert to an absolute value.

Applies To

The abs function can be used in the following versions of PostgreSQL:

  • PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4

Example

Let's look at some PostgreSQL abs function examples and explore how to use the abs function in PostgreSQL.

For example:

postgres=# SELECT abs(-23);
 abs
-----

  23
(1 row)

postgres=# SELECT abs(-23.6);
 abs
------

 23.6
(1 row)

postgres=# SELECT abs(-23.65);
  abs
-------

 23.65
(1 row)

postgres=# SELECT abs(23.65);
  abs
-------

 23.65
(1 row)

postgres=# SELECT abs(30 * -1);
 abs
-----

  30
(1 row)