// math reference

SQL PI function

Returns an approximation of pi, about 3.141592653589793, as a floating point value.

Category
Math
Returns
float / double
In this category
29 of 82

Syntax

PI()

Engine support

EngineSupportNotes
SQL Server Yes Supported under this name.
PostgreSQL Yes Supported under this name.
MySQL Yes Displays 3.141593 (six decimals) by default, but the value used in arithmetic is the full double
SQLite Yes Requires SQLite 3.35+ with the math functions built in
Oracle Not built in No PI() in any release, 23ai included (ORA-00904); use ACOS(-1)

Examples

PostgreSQL

SELECT PI() AS pi;  -- 3.141592653589793

MySQL

SELECT PI() AS shown, PI() + 0.0000000000 AS more_digits;  -- 3.141593, 3.1415926536

SQL Server

SELECT RADIUS, PI() * SQUARE(RADIUS) AS area
FROM circles;

Oracle

SELECT ACOS(-1) AS pi FROM dual;  -- Oracle has no PI()

Good to know

  • PI() is a double: 15-17 significant digits, so it is close to but not exactly pi. Formulas inherit that precision.
  • TAN(PI()/2) is not an error or infinity: PI()/2 is only approximately a right angle in floats, so the tangent is a huge finite number.
  • MySQL prints PI() as 3.141593, which looks like a truncated constant. Only the display is short: PI() + 0.0000000000 shows 3.1415926536, and formulas use the full double.

Questions about PI

What does PI() return exactly?

The double nearest to pi, 3.141592653589793, accurate to about 16 digits. MySQL displays it as 3.141593 but computes with the full value.

How do I get pi on Oracle?

SELECT ACOS(-1) FROM dual. Oracle has no PI() function in any release, 23ai included. ACOS(-1) on NUMBER returns pi to NUMBER precision, about 38 digits, more than a double carries.

Why is TAN(PI()/2) a huge number instead of infinity?

PI()/2 in double precision is not exactly a right angle, it is a few units in the last digit off, so the tangent is finite and enormous rather than undefined.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.