Lesson

MySQL PI() Function

10 min reading
Free Course

MySQL PI() Function: Using the Pi Constant in SQL Queries

The PI() function returns the mathematical constant pi (3.141593 by default display) as a double-precision floating-point number. It takes zero arguments and always evaluates to the same constant.

You will use PI() when computing circular dimensions (circumference, area, cylinder volume), converting between degrees and radians manually, or building spherical distance queries across geographic points.

Syntax

PI()
  • Takes no arguments. Passing any value inside the parentheses causes a syntax error.

Practical Example

Suppose demo_products sells circular dining tables and round rugs listed by radius_cm. You can compute each item's circumference (2 * PI() * r) and surface area (PI() * r * r) directly in SQL.

SELECT
    product_id,
    product_name,
    radius_cm,
    ROUND(2 * PI() * radius_cm, 2) AS circumference_cm,
    ROUND(PI() * POW(radius_cm, 2), 2) AS area_sq_cm
FROM demo_products
WHERE radius_cm IS NOT NULL;
product_id product_name radius_cm circumference_cm area_sq_cm
81 Round Oak Table 60.0 376.99 11309.73
82 Wool Circle Rug 90.0 565.49 25446.90
83 Small Side Table 25.0 157.08 1963.50

Notice that ROUND(..., 2) formats the double-precision product cleanly into two decimal places for product specification sheets.

Common Mistakes & NULL Behavior

  • Passing an argument to PI(): Writing PI(10) or PI(NULL) throws ERROR 1582 (42000): Incorrect parameter count in the call to native function 'PI'. Always leave the parentheses empty: PI().
  • Confusing display decimals with internal precision: Running SELECT PI(); prints 3.141593 (6 decimal places by default in MySQL clients), yet MySQL stores 3.141592653589793 internally as a DOUBLE for accurate math.
  • No NULL inputs possible: Because PI() accepts zero arguments, it never receives NULL directly. Multiplying PI() * radius_cm only returns NULL if radius_cm itself is NULL.

Frequently Asked Questions

How do I display more than 6 decimal places of PI() in MySQL?

Add 0.000000000000000 or use FORMAT(PI(), 15) or CAST(PI() AS DECIMAL(17, 15)) to inspect full internal precision (3.141592653589793).

Does PI() differ across MySQL platforms?

Internally, PI() represents the standard IEEE 754 DOUBLE approximation of pi (M_PI), so results are consistent across modern 64-bit servers.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum