In celebration of Pi Day, I asked SingleStore’s Engineering team to come up with clever ways to compute pi in SQL. Because that’s the kind of thing we engineers enjoy! And, given pi’s privileged status in mathematical history – and my own history of earning a bachelor’s degree in Mathematics – I just couldn’t resist.
Truth be told, in the early days of SingleStore, my fellow math geeks and I had some fun with Pi Day – yes, including eating actual pies – and we even had a colleague with the nickname of Pieguy. Pie, not Pi, btw. So, if anyone was going to put together a blog post on calculating pi in honor of Pi Day, it would be me.
How else is SingleStore Pi/Pie-forward? Here are a few fun facts:
That being said, we had fun putting this post together, and we hope you have a great #piday.
Let’s Use Stored Procedures_Code is available [in Github](https://gist.github.com/carlsverre/08fcd301faa1bbb2f3fe7bc80da62d4a)._
Let’s Generate a Large(-ish) Dataset with Some Random Data
From there, the conversation digressed into the quality of our RAND() implementation and our engineers started to compare it with loading data from /dev/urandom with data generated by calling RAND().
We Also Got an Alternative Solution
This one outputs pie – the author says it is a pecan pie, but it’s hard to tell for sure.
This is all fun and good, but of course you can just do:
memsql> select PI(); +-------------------+ | PI() | +-------------------+ | 3.141593 | +-------------------+ 1 row in set (0.00 sec)
Thank you all for reading! Now, time for some cherry pie.
With thanks to Carl Sverre for graphics and code storage.