Skip to content

Instantly share code, notes, and snippets.

@rivalitaet
rivalitaet / fibonacci.sql
Last active April 28, 2016 11:11
Creates fibonacci numbers directly in postgreSQL
WITH RECURSIVE fibs(val, tmp) as (
SELECT 1::NUMERIC, 1::NUMERIC UNION ALL
SELECT tmp, val + tmp FROM fibs
)
SELECT val FROM fibs limit 100
@rivalitaet
rivalitaet / primes.sql
Last active April 27, 2016 00:58
Primes generated with postgreSQL, unfortunately not very fast yet
WITH ps(v) as (
WITH RECURSIVE t(v) as (
SELECT 3::NUMERIC UNION ALL
SELECT v+2 FROM t
)
SELECT v from t limit 1000
)
SELECT 2 UNION ALL
SELECT v as prime from ps as candidate
WHERE NOT EXISTS (