Optimization, Native in SQL
PackDB extends DuckDB with declarative optimization. Select optimal subsets of data with constraints and objectives — no external tools required.
SELECT item, value, weight, x AS selected
FROM Items
DECIDE x IS BOOLEAN
SUCH THAT
SUM(x * weight) <= 50
MAXIMIZE SUM(x * value);
One query. No data export. No solver code. Just SQL.
Why Optimization Belongs in the Database
Many real-world decisions require choosing the best subset of items from a table — which products to stock, which patients to schedule, which assets to include. Today, solving these package queries means exporting data, writing solver code in Python, and mapping results back. PackDB collapses that entire pipeline into a single SQL statement.
# Step 1: Export data from database
import duckdb, pulp
conn = duckdb.connect('db.duckdb')
items = conn.execute("""
SELECT id, value, weight FROM Items
WHERE category = 'electronics'
""").fetchall()
# Step 2: Build optimization model
prob = pulp.LpProblem("knapsack", pulp.LpMaximize)
x = [pulp.LpVariable(f"x_{i}", cat='Binary')
for i in range(len(items))]
# Step 3: Add constraints + solve
prob += pulp.lpSum(
x[i] * items[i][2] for i in range(len(items))
) <= 50
prob += pulp.lpSum(
x[i] * items[i][1] for i in range(len(items))
)
prob.solve()
# Step 4: Map results back to database...
-- One query does it all
SELECT id, value, weight, x
FROM Items
WHERE category = 'electronics'
DECIDE x IS BOOLEAN
SUCH THAT
SUM(x * weight) <= 50
MAXIMIZE SUM(x * value);
Same result, a fraction of the code. No context switching between languages.
Built for Complex Selection Problems
Any problem where you need to pick the best subset from a table — subject to constraints — is a package query.
Why PackDB?
Native SQL
Express optimization as a SQL extension. No context switching.
Zero Data Movement
Solve directly on database buffers. No export/import overhead.
Declarative
Define what to optimize, not how. The system handles formulation.
Built on DuckDB
Columnar storage, vectorized execution, embedded HiGHS solver.