PostgreSQL PI() Function
PostgreSQL PI() Function
The PostgreSQL PI()
function is used to return the value of π (pi). This function is essential for mathematical computations involving circles, trigonometry, and various geometric calculations.
Syntax
PI()
The PI()
function does not take any arguments and returns the value of π, approximately 3.141592653589793.
Example PostgreSQL PI() Queries
Let's look at some examples of PostgreSQL PI()
function queries:
1. Basic PI() Example
SELECT PI() AS pi_value;
This query returns the value of π, which is approximately 3.141592653589793.
2. PI() in Area Calculation
SELECT radius, PI() * radius * radius AS area
FROM circles;
This query calculates the area of circles stored in the circles
table using the formula πr².
3. PI() in Circumference Calculation
SELECT radius, 2 * PI() * radius AS circumference
FROM circles;
This query calculates the circumference of circles stored in the circles
table using the formula 2πr.