Return the mathematical constant pi (approximately 3.14159265358979).
PI()
## Overview Returns the mathematical constant pi as a DOUBLE. PI is a niladic function (it takes no arguments) and is the standard way to access the ratio of a circle's circumference to its diameter in SQL. Use PI() in area, circumference, volume, and angle-conversion calculations. The returned value is the closest DOUBLE to the mathematical pi, which is approximately 3.141592653589793. It is not exact: pi is an irrational number and cannot be represented exactly in any finite-precision floating-point format. ## Behavior - Takes no arguments. - Returns a DOUBLE with the closest representable value to pi. - Deterministic: every call in every session returns the same DOUBLE. - Matches the pi constant used internally by SIN, COS, TAN, ASIN, ACOS, ATAN, and ATAN2. ## Numeric precision - The returned DOUBLE is the correctly rounded approximation of pi to double precision. - The error versus true pi is less than 2^-53 in relative terms. - For applications requiring extended precision (astronomy, high-precision geometry), compute in DECIMAL or arbitrary-precision arithmetic rather than relying on DOUBLE pi. ## Compatibility - Conforms to the SQL standard niladic function PI(). - Matches the IEEE 754 double-precision value of pi used by typical mathematical libraries.
-- Return the value of pi
SELECT PI();
-- Result: 3.141592653589793
-- Compute circumference of a circle with radius 5
SELECT 2 * PI() * 5;
-- Result: 31.41592653589793
-- Compute area of a circle with radius 3
SELECT PI() * POW(3, 2);
-- Result: 28.274333882308138
-- Use in angle conversion
SELECT DEGREES(PI() / 4);
-- Result: 45.0
-- Volume of a sphere with radius r
SELECT (4.0 / 3.0) * PI() * POW(2, 3) AS sphere_volume;
-- Result: 33.510321638291124
-- Column use: compute arc length from a radius and angle (in radians)
SELECT arc_id, radius_m * angle_rad AS arc_length_m,
radius_m * PI() * 2 AS full_circle_m
FROM geometry.samples.arcs;