PostgreSQL Math Functions

This page provides you with the most commonly used PostgreSQL Math functions that help you perform various math operations quickly and effectively.

FunctionDescriptionExampleResult
ABSCalculate the absolute value of a numberABS(-10)10
CBRTCalculate the cube root of a numberCBRT(8)2
CEILRound a number up to the nearest integer, which is greater than or equal to a specified numberCEIL(-12.8)-12
CEILINGSame as CEIL
DEGREESConvert radians to degreesDEGREES(0.8)45.83662361
DIVReturn the integer quotient of two numeric valuesDIV(8,3)2
EXPReturn the exponential value in the scientific notation of a numberEXP(1)2.718281828
FLOORRound a number down to the nearest integer, which is less than or equal to the numberFLOOR(10.6)10
LNReturn the natural logarithm of a numeric valueLN(3)1.098612289
LOGReturn the base 10 logarithms of a numeric valueLOG(1000)3
LOGReturn the logarithm of a numeric value to a specified baseLOG(2, 64)6
MODDivide the first parameter by the second one and return the remainderMOD(10,4)2
PIReturn the value of PIPI()3.141592654
POWERRaise a numeric value to the power of a second numeric valuePOWER(5, 3)125
RADIANSConvert degrees to radiansRADIANS(60)1.047197551
ROUNDRound a number to the nearest integer or to a specified decimal placesROUND(10.3)10
SCALEReturn the number of decimal digits in the fractional partSCALE(1.234)3
SIGNReturn the sign (positive, negative) of a numeric valueSIGN(-1)-1
SQRTReturn the square root of a numeric valueSQRT(3.0)1.732050808
TRUNCTruncate a numeric value to a whole number of the specified decimal placesTRUNC(12.3)12
WIDTH_BUCKETAssign values to buckets in an equi-width histogram.
RANDOMReturn a random number that ranges from 0 to 10.968435665