w3resource logo


postgresql mathematical Function Operators

PostgreSQL Mathematical Functions

rating PostgreSQL Mathematical Functions has average rating 6 out of 10. Total 2 users rated.

<<PreviousNext>>

Description

A mathematical function operates on input values ( numeric ) which are provided as arguments, and returns a numeric value as the output of that operation. Mathematical functions operates on numeric data.

List of Mathematical Functions

Functions Example Output
abs ( ) abs(-115.36) 115.36
cbrt( ) cbrt ( 343) 7
ceil( ) ceil(-53.7 ) -53
ceiling( ) ceiling(-69.8 ) -69
degrees( ) degrees( .45) 25.783100780887
div( ) div( 19 , 3) 6
exp( ) exp( 2.0 ) 7.3890560989306502
floor( ) floor(-53.6 ) -54
ln( ) ln( 3.0) 1.0986122886681097
log( ) log(200.0 ) 2.3010299956639812
mod( ) mod( 38,5) 3
pi( ) pi( ) 3.14159265358979
power( ) power(7,3 ) 343
radians( ) radians(15.0 )
0.261799387799149
random( ) random( )  
round( ) round( 67.456) 67
sign( ) sign(-14.321 ) -1
sqrt( ) sqrt(225 ) 15
trunc( ) trunc(67.456 ) 67

PostgreSQL abs() function

The PostgreSQL abs() returns the absolute value of a number passed as argument.

SQL


SELECT ABS(-115.36) AS "Absolute Value", ABS(115.36) AS "Absolute Value";

              

Output

PostgreSQL abs() function

PostgreSQL cbrt() function

The PostgreSQL cbrt() returns the cube root of a given number.

SQL


SELECT CBRT(343) AS "Cube Root", CBRT(-343) AS "Cube Root";

              

Output

PostgreSQL cbrt() function

PostgreSQL ceil() function

The PostgreSQL ceil() will rounded up any positive or negative decimal value and return the value as greater than the argument.

SQL


SELECT CEIL(-53.7) AS "Ceil", CEIL(53.7) AS "Ceil";

              

Output

PostgreSQL ceil() function

PostgreSQL ceiling() function

The PostgreSQL ceiling() will rounded up any positive or negative decimal value and return the value as greater than the argument.

SQL


SELECT CEILING(-69.8) AS "Ceiling", CEILING(69.4) AS "Ceiling";

              

Output

PostgreSQL ceiling() function

PostgreSQL degrees() function

The PostgreSQL degrees() will return the values in degrees from radian as specified in the argument.

SQL


SELECT DEGREES(.45) AS "Degrees";

              

Output

PostgreSQL degrees() function

PostgreSQL div() function

The PostgreSQL div() will return the integer quotient of a division as specified in the argument.

SQL


SELECT DIV(19,3) AS "Quotient", DIV(-27,5) AS "Quotient";

              

Output

PostgreSQL div() function

PostgreSQL exp() function

The PostgreSQL exp() will return the exponentiation of a number as specified in the argument.

SQL


SELECT EXP(2.0) AS "Exponential";

              

PostgreSQL exp() function

PostgreSQL floor() function

The PostgreSQL floor() will rounded up any positive or negative decimal value and return the value as smaller than the argument.

SQL


SELECT FLOOR(-53.6) AS "Floor",FLOOR(53.6) AS "Floor";

              

PostgreSQL floor() function

PostgreSQL ln() function

The PostgreSQL ln() will return the natural logarithm of a given number, as specified in the argument.

SQL


SELECT LN(3.0) AS "Natural Logarithm";

              

PostgreSQL ln() function

PostgreSQL log() function

The PostgreSQL log() will return the base 10 logarithm of a given number or logarithm of a number for a particular base, as specified in the argument.

SQL


SELECT LOG(200.0) AS "Base 10 Logarithm",LOG(2.0,16) AS "Base 2 Logarithm";

              

PostgreSQL log() function

PostgreSQL mod() function

The PostgreSQL mod() will return the remainder of a division of two numbers, as specified in the argument.

SQL


SELECT MOD(38,5) AS "Remainder",MOD(-38,5) AS "Remainder";

              

PostgreSQL mod() function

PostgreSQL pi() function

The PostgreSQL pi() will return the constant value of pi.

SQL


SELECT PI() AS "Value of PI";

              

PostgreSQL pi() function

PostgreSQL power() function

The PostgreSQL power() will return the value of one number raised to the power of another number, provided in the argument.

SQL


SELECT POWER(7.0,3) AS "7 raised to the power of 3",POWER(7,3) AS "7 raised to the power of 3";

              

PostgreSQL power() function

PostgreSQL radians() function

The PostgreSQL radians() will return the value in radian from degrees, provided in the argument.

SQL


SELECT RADIANS(15.0) AS "Degrees to Radians";

              

PostgreSQL radians() function

PostgreSQL random() function

The PostgreSQL random() will return the random value between 0 and 1.

SQL


SELECT RANDOM() AS "Random Numbers";

              

PostgreSQL random() function

PostgreSQL round() function

The PostgreSQL round() will return the value after rounded a number upto a specific decimal places, provided in the argument.

SQL


SELECT ROUND(67.456) AS "Round",ROUND(67.456,1) AS "Round upto 1 decimal",ROUND(67.456,2) AS "Round upto 2 decimal";

              

PostgreSQL round() function

PostgreSQL sign() function

The PostgreSQL sign() will return the sign of a given number. It returns 1 if the number is positive and -1 if negative.

SQL


SELECT SIGN(14.321) AS "Positive Number",SIGN(-14.321) AS "Negative Number";

              

PostgreSQL sign() function

PostgreSQL sqrt() function

The PostgreSQL sqrt() will return the square root of a given positive number.

SQL


SELECT SQRT(225) AS "Square Root";

              

PostgreSQL sqrt() function

PostgreSQL trunc() function

The PostgreSQL trunc() will truncate a number to a particular decimal places. If no decimal places is provided it truncate toward zero(0).

SQL


SELECT TRUNC(67.456) AS "Truncate", TRUNC(67.456,1) AS "Truncate upto 1 decimal", TRUNC(67.456,2) AS "Truncate upto 2 decimal";

              

PostgreSQL trunc() function



<<PreviousNext>>