The PI Function in YSQL

Pi Day 2024 is today (Thursday, March 14, 2024)!

We all know that the irrational number π is a mathematical constant that is the ratio of a circle’s circumference to its diameter.

Most databases provide a built in function that can be used to display a representative value of PI. I thought it would be fun to check a few databases to see which one serves up the most accurate juiciest slice of PI by default!

MySQL returns 14 digits:

Oracle does not have a PI function, but we can simulate it using one of the following two techniques where the first one is more accurate to 8 digits:

				
					SQL> SELECT asin(1)*2 FROMm dual;
 ASIN(1)*2
----------
3.14159265

SQL> SELECT 22/7 FROM dual;
   22/7
----------
3.14285714
				
			

Vertica returns a whopping 50 decimal places from the PI() function!

				
					dbadmin=> SELECT pi();
                           pi
------------------------------------------------------
3.14159265358979323846264338327950288419716939937510
(1 row)
				
			

PostgreSQL is like MySQL in that it also returns 14 decimal values:

				
					postgres=# SELECT pi();
        pi
------------------
 3.14159265358979
(1 row)
				
			

What about the YugabyteDB YSQL API? The same as PostgreSQL ofcourse; YSQL is compatble with PostgreSQL!

				
					yugabyte=# SELECT pi();
        pi
------------------
 3.14159265358979
(1 row)
				
			

Have Fun!