Last active
April 27, 2016 00:58
-
-
Save rivalitaet/e37d4ec5b9f1705aff6a3d575ff35162 to your computer and use it in GitHub Desktop.
Primes generated with postgreSQL, unfortunately not very fast yet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( | |
SELECT * FROM ps WHERE | |
(v*v) <= candidate.v AND | |
candidate.v % v = 0 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment