EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL Math Functions

PostgreSQL Math Functions

Sohel Sayyad
Article bySohel Sayyad
Priya Pedamkar
Reviewed byPriya Pedamkar

Updated May 8, 2023

PostgreSQL Math Functions

Introduction to PostgreSQL Math Functions

The following article provides an outline of PostgreSQL Math Functions. PostgreSQL provides us with various mathematical functions to manipulate the values. The mathematical function returns us the numeric value as a result of the operation. It takes input values ( numeric ) as input which are given as arguments to the mathematical function. The functions are used to get constant values as well, like PI(3.14). There can be a mathematical function that has multiple forms with different parameters as input.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Different PostgreSQL Math Functions

Given below are different Functions:

1. abs(number)

As a result, we will get the absolute value of a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

select abs(-260) AS abs_number;

Output:

postgreSQL Math Functions 1

2. asin(number)

As a result, we will get the inverse sine of a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT asin(1), asin(0), asin(-1), asin(sin(1)) AS inverse_sine_result;

Output:

postgreSQL Math Functions 2

3. atan(number)

As a result, we will get the inverse tangent of a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

select atan(tan(1)) AS inverse_tan_result;

Output:

postgreSQL Math Functions 3

4. cbrt(number)

As a result, we will get the cube root of a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT cbrt(27.0) AS "twenty seven's cube root";

Output:

cbrt(number)

5. cos(number)

As a result, we will get the cosine of a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT cos(pi()) AS cos_of_pi, cos(0) AS cos_of_zero;

Output:

cos(number)

6. cot(number)

Returns the cotangent of a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT cot(1) as cot_of_one, cot(-1) as cot_of_neg_one;

Output:

cot(number)

7. ceil(number)

As a result, we will get the smallest whole integer not less than a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT ceil(-41.2);

Output:

 ceil(number)

8. degrees(rad)

As a result, we will get degrees from radians rad.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT degrees(acos(-1)) AS hlf_circle, degrees(pi() * 2) AS fl_circle;

Output:

postgreSQL Math Functions 8

9. exp(numeric)

As a result, we will get the exponential value in the scientific notation of a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT exp(1.0) AS exp_one;

Output:

postgreSQL Math Functions 9

10. floor(number)

As a result, we will get the round of a number down to the nearest value, which is less than or equal to the specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

select floor(-43.7);

Output:

floor(number)

11. isfinite()

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT isfinite('now'::timestamp) AS now_is_finite_time, isfinite('infinity'::timestamp) AS infinity_time;

Output:

isfinite()

12. ln(number)

As a result, we will get the natural logarithm of a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT ln(4);

Output:

ln(number)

13. log(base, number)

As a result, we will get the logarithm of a specified number to a specified base.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

select LOG(3, 81);

Output:

postgreSQL Math Functions 13

14. MOD(number1,number2)

As a result, we will divide the first number by the second number and return the remainder.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

select MOD(20,8);

Output:

postgreSQL Math Functions 14

15. pi()

As a result, we will get the constant PI as (3.14159).

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

select PI();

Output:

postgreSQL Math Functions 15

16. POWER(number1,number2)

As a result, we will raise the first number to the power of a second number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

select POWER(4, 2);

Output:

postgreSQL Math Functions 16

17. radians(deg)

As a result, we will get the radian value equivalent to a specified deg degree.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

select RADIANS(90);

Output:

postgreSQL Math Functions 17

18. random()

As a result, we will get a random number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT random();

Output:

postgreSQL Math Functions OP 18JPG

19. round(number)

As a result, we will get a number rounded to the nearest whole value.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT round(2.0) AS "two",
round(2.5) AS "two point five",
round(2.6) AS "two point six",
round(2.7) AS "two point seven";

Output:

postgreSQL Math Functions 19

20. SCALE(number)

As a result, we will get the number of decimal digits in the fractional part.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT SCALE(2.321);

Output:

SCALE(number)

21. sqrt(number)

As a result, we will get the square root of a specified number.

Illustrate the following SQL statement and snapshot to understand the above function.

Code:

SELECT sqrt(9.0), sqrt(16.0), sqrt(pow(4.0, 2));

Output:

sqrt(number)

Conclusion

From the above article, you have understood how to use the PostgreSQL mathematical functions and how the PostgreSQL mathematical functions work. Also, we have added some examples of PostgreSQL mathematical functions to understand them in detail.

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL Math Functions” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. PostgreSQL LIMIT
  2. ROLLUP PostgreSQL
  3. PostgreSQL Alias
  4. PostgreSQL OFFSET
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
Financial Analyst Masters Training Program
2000+ Hours of HD Videos
43 Learning Paths
550+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Data Science Bundle
2000+ Hour of HD Videos
80 Learning Paths
400+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Software Development Bundle
5000+ Hours of HD Videos
149 Learning Paths
1050+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
All in One Data Science Bundle2000+ Hour of HD Videos | 80 Learning Paths | 400+ Courses | Verifiable Certificate of Completion | Lifetime Access
Financial Analyst Masters Training Program2000+ Hours of HD Videos | 43 Learning Paths | 550+ Courses | Verifiable Certificate of Completion | Lifetime Access
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more