PostgreSQL PI() Function
Summary: in this tutorial, you will learn how to use the PostgreSQL PI()
function to return the pi value.
Introduction to the PostgreSQL PI() function
In PostgreSQL, the PI()
function returns the value of pi denoted by the Greek letter (π), which is approximately equal to 3.14
Here’s the syntax of the PI()
function:
The PI
() function takes no arguments and returns the constant value of PI
, which is 3.141592653589793
.
PostgreSQL PI() function examples
Let’s take some examples of using the PI()
function examples.
1) Basic PI() function examples
The following statement uses the PI()
function to return the constant PI
value:
Output:
The following example uses the PI()
function to calculate the area of a circle with a radius of 10:
Output:
2) Using the PI() function with table data
First, create a table called circles
that stores the radiuses of circles:
Second, insert rows into the circles
table:
Output:
Third, calculate the areas of circles using the PI()
function:
Output:
To make the area more readable, you can use the ROUND()
function:
Output:
Summary
- Use the
PI()
function to return the pi value.