Skip to content

Instantly share code, notes, and snippets.

@ccamel
Created March 21, 2019 16:46
Show Gist options
  • Save ccamel/4ce87632e3ac1f20748015baf864722c to your computer and use it in GitHub Desktop.
Save ccamel/4ce87632e3ac1f20748015baf864722c to your computer and use it in GitHub Desktop.
Computation of π with PostgreSQL Recursive Query
-- just for fun
-- compute π using the Leibniz formula
with recursive leibniz (n, r) as (
select 0, 0.
union
select n + 1, r + cast(power(-1, n) as decimal) / (2. * n + 1.)
from leibniz
where n < 10000
)
select 4. * r as pi from numbers offset 10000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment