Native CP-SAT constraint solving and GLOP linear optimization with relational resource allocation
Compatibility Matrix
This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.
| Platform | 1.4.4 | 1.4.5 | 1.5.5 | 1.5.6 | 2.0.0 |
|---|---|---|---|---|---|
| Linux AMD64 | |||||
| Linux ARM64 | |||||
| macOS AMD64 | |||||
| macOS ARM64 | |||||
| Windows AMD64 | |||||
| Windows ARM64 | |||||
| WebAssembly |
Installing and Loading
INSTALL ortools FROM community;
LOAD ortools;
Example
INSTALL ortools FROM community;
LOAD ortools;
WITH solved AS (
SELECT ortools_solve('{
"version": 1,
"solver": "cp_sat",
"maximize": true,
"variables": [{"id": "x", "upper": 4, "objective": 2}],
"constraints": []
}') AS solution
)
SELECT solution.status, solution.values['x'] AS x, solution.objective
FROM solved;
-- OPTIMAL | 4.0 | 8.0
About ortools
Solve optimization models directly in DuckDB SQL using native C++ OR-Tools. No API key, hosted solver, or Python solver runtime is required.
ortools_solve accepts a versioned JSON model and returns a typed solution
struct containing status, objective, bound, decision values, timing, and
infeasibility diagnostics. CP-SAT handles integer and Boolean constraints;
GLOP handles continuous linear optimization. ortools_allocate supports
relational allocation with capacity and demand shared across input chunks.
Active searches honor DuckDB query cancellation.
The community build is self-contained: its pinned, minimal OR-Tools
dependencies are statically linked. Gurobi, CPLEX, Xpress, COIN-OR, GLPK,
SCIP, HiGHS, and PDLP are disabled. License and modification notices are
embedded and readable with SELECT ortools_licenses();.
Model reference, examples, and dependency policy: https://github.com/prasanthj/duckdb-ortools
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| ortools_allocate | table | NULL | NULL | |
| ortools_licenses | scalar | NULL | NULL | |
| ortools_solve | scalar | NULL | NULL | |
| ortools_version | scalar | NULL | NULL |
Overloaded Functions
This extension does not add any function overloads.
Added Types
This extension does not add any types.
Added Settings
| name | description | input_type | scope | aliases | typed_value |
|---|---|---|---|---|---|
| temp_directory | Set the directory to which temporary files are written. | VARCHAR | GLOBAL | [] | post.db.tmp |