A table of prime numbers, because why not
I asked for system.primes holding the first million primes. It shipped in 26.2 as something better: an infinite, computed table and a primes() table function.
Source: github.com
This one was about a dataset, not a pain. Primes are a famous sequence that needs no explanation in a talk or a benchmark, and ClickHouse already had numbers() for the integers. Computing primes in SQL is an ugly query (mine was a recursive CTE with trial division, which also hit the recursion-depth limit I filed as #90838). I asked for a system.primes table holding the first million primes, with an index column.
The maintainers did better. PR #92776 by nihalzp, “New table function primes and system.primes”, merged on 2026-01-27 and shipped in 26.2. Instead of a stored, bounded table it is virtual like numbers: primes are generated on demand, in ascending order, with no upper limit, plus a primes() table function taking a limit or an offset and a limit. I lost the index column and gained not storing anything. If you need the index, row_number() OVER () over a limited selection gives it back.
On 26.4:
SELECT prime FROM primes(3, 4); -- 7, 11, 13, 17
SELECT prime FROM system.primes WHERE prime > toUInt64(1e15) LIMIT 1;
1000000000000037
My original request is one OFFSET away: SELECT prime FROM primes() LIMIT 1 OFFSET 999999 returns 15485863, the millionth prime.
Discussion
Comments live in GitHub Discussions. Sign in with GitHub to join in.