PostgreSQL Mathematical Functions

Below table shows the available PostgreSQL Mathematical Functions with examples.

Function Return Type Description Example Result
2
abs( x )
(same as input)
absolute value abs(-17.4) 17.4
3
cbrt( dp ) dp cube root cbrt(27.0) 3
4
ceil( dp or numeric )
(same as input)
smallest integer not less than argument
ceil(-42.8) -42
5
ceiling( dp or numeric )
(same as input)
smallest integer not less than argument (alias for ceil )
ceiling(-95.3) -95
6
degrees( dp ) dp
radians to degrees
degrees(0.5) 28.64788976
7
div( y numeric , x numeric )
numeric
integer quotient of y / x
div(9,4) 2
8
exp( dp or numeric )
(same as input)
exponential exp(1.0) 2.718281828
9
floor( dp or numeric )
(same as input)
largest integer not greater than argument
floor(-42.8) -43
10
ln( dp or numeric )
(same as input)
natural logarithm
ln(2.0) 0.6931471806
11
log( dp or numeric )
(same as input)
base 10 logarithm
log(100.0) 2
12
log( b numeric , x numeric )
numeric
logarithm to base b
log(2.0, 64.0) 6
13
mod( y , x )
(same as argument types)
remainder of y / x
mod(9,4) 1
14
pi() dp "π" constant pi() 3.141592654
15
power( a dp , b dp )
dp
a raised to the power of b
power(9.0, 3.0) 729
16
power( a numeric , b numeric )
numeric
a raised to the power of b
power(9.0, 3.0) 729
17
radians( dp ) dp
degrees to radians
radians(45.0) 0.7853981634
18
round( dp or numeric )
(same as input)
round to nearest integer
round(42.4) 42
19
round( v numeric , s int )
numeric
round to s decimal places
round(42.4382, 2)
42.44
20
sign( dp or numeric )
(same as input)
sign of the argument (-1, 0, +1)
sign(-8.4) -1
21
sqrt( dp or numeric )
(same as input)
square root sqrt(2.0) 1.414213562
22
trunc( dp or numeric )
(same as input)
truncate toward zero
trunc(42.8) 42
23
trunc( v numeric , s int )
numeric
truncate to s decimal places
trunc(42.4382, 2)
42.43
24
width_bucket( op numeric , b1 numeric , b2 numeric , count int )
int
return the bucket to which operand would be assigned in an equidepth histogram with count buckets, in the range b1 to b2
width_bucket(5.35, 0.024, 10.06, 5)
3
25
width_bucket( op dp , b1 dp , b2 dp , count int )
int
return the bucket to which operand would be assigned in an equidepth histogram with count buckets, in the range b1 to b2
width_bucket(5.35, 0.024, 10.06, 5)
3

Other PostgreSQL Mathematical functions are Trigonometric Functions: cos(),sin(),tan(),cot(),acos(),asin(),atan(),acot().