Skip to content

Instantly share code, notes, and snippets.

@homuler
homuler / prime_sieves.sql
Last active December 29, 2022 12:57
Sieving Prime Numbers in SQL (PostgreSQL 9.6)
-- Enumerate prime numbers below N using only SQL
-- DDL
create table primes(
value integer primary key,
sieved boolean not null default false
);
create index prime_sieve_idx on
primes(value, sieved);