Monday , August 5 2024

# PostgreSQL Math Functions

In today’s article, we will be talking about the most used PostgreSQL Mathematical and Numerical Functions.

PostgreSQL numeric functions are used primarily for numeric manipulation and/or mathematical calculations.

The functions and their explanations are shown below.

ABS(): Returns the absolute value of numeric expression.

ACOS(): Returns the arccosine of numeric expression. Returns NULL if the value is not in the range -1 to 1.

ASIN(): Returns the arcsine of numeric expression. Returns NULL if value is not in the range -1 to 1.

ATAN(): Returns the arctangent of numeric expression.

ATAN2(): Returns the arctangent of the two variables passed to it.

CEIL(): Returns the smallest integer value that is not less than passed numeric expression

CEILING(): Returns the smallest integer value that is not less than passed numeric expression

COS(): Returns the cosine of passed numeric expression. The numeric expression should be expressed in radians.

COT(): Returns the cotangent of passed numeric expression.

DEGREES(): Returns numeric expression converted from radians to degrees.

EXP(): Returns the base of the natural logarithm (e) raised to the power of passed numeric expression.

FLOOR(): Returns the largest integer value that is not greater than passed numeric expression.

GREATEST(): Returns the largest value of the input expressions.

LEAST(): Returns the minimum-valued input when given two or more.

LOG(): Returns the natural logarithm of the passed numeric expression.

MOD(): Returns the remainder of one expression by diving by another expression.

PI(): Returns the value of pi

POW(): Returns the value of one expression raised to the power of another expression

POWER(): Returns the value of one expression raised to the power of another expression

RADIANS(): Returns the value of passed expression converted from degrees to radians.

ROUND(): Returns numeric expression rounded to an integer. Can be used to round an expression to a number of decimal points

SIN(): Returns the sine of numeric expression given in radians.

SQRT(): Returns the non-negative square root of numeric expression.

TAN(): Returns the tangent of numeric expression expressed in radians.

You can use the above functions as follows.