It’s Pi Day! Let’s calculate pi using SQL
Happy Pi Day! We thought it would be fun to calculate pi using SQL queries in ClickHouse. Here is what we came up with so far…- This one uses the ClickHouse
numbers_mttable function to return 1B rows and only takes 40ms to compute the calculation:
- The following example also processes 1B numbers, just not as quickly:
- This one is obviously our favorite in ClickHouse (and the most accurate!):
- Someone knew their trigonometry with this one:
- Here is a handy API that lets you specify the number of digits you want:
- This one is clever - it uses ClickHouse distance functions:
- If you’re a physicist, you will be content with this one:
- Another indirect method (this one came from Alexey Milovidov) that is accurate to 7 decimal places - and it’s quick:
If you have any more, we’d love for you to contribute. Thanks!