Skip to main content

DeciDB

Optimization, Native in SQL

DeciDB extends SQL with a DECIDE clause for declarative in-database optimization. Express constrained optimization problems directly in SQL — no external solver, no data export, no context switching.

A research project by HUDA Lab at NYU Abu Dhabi.

Install

pip install decidb

Wheels are published for Linux x86-64, macOS arm64, and Windows AMD64 on Python 3.11–3.13. DeciDB is a fork of DuckDB, so the Python API is DuckDB's.

Quick Example

A knapsack: pick the most valuable items that fit in the weight budget.

import decidb

conn = decidb.connect()
conn.execute("""
    CREATE TABLE Items (id INTEGER, value INTEGER, weight INTEGER);
    INSERT INTO Items VALUES (1, 100, 20), (2, 60, 10), (3, 120, 30);
""")

print(conn.execute("""
    SELECT id, value, weight, x
    FROM Items
    DECIDE x(BOOL)
    SUCH THAT SUM(x * weight) <= 50
    MAXIMIZE SUM(x * value)
""").fetchall())

x comes back as 1 for chosen rows and 0 for the rest. The equivalent with an external modelling library means exporting the table, rebuilding it as variables, solving, and joining the answer back by hand.

Choosing rows is only the simplest case. INT and REAL decisions assign a quantity to every row, which is what most real problems need — here, how many units to produce at each plant to meet demand at the lowest cost:

SELECT plant, units
FROM Plants
DECIDE units(INT)
SUCH THAT units <= capacity
      AND SUM(units) >= 500
MINIMIZE SUM(units * unit_cost)

The DECIDE Clause

SELECT select_list
FROM table_expression
[WHERE ...]
DECIDE [Table.]variable_name(TYPE) [, ...]
SUCH THAT constraint [AND constraint ...]
[MAXIMIZE | MINIMIZE] objective_expression

The declaration may also sit between SELECT and FROM; the two orders parse to the same plan. SUCH THAT is required.

Decision Variables

The type is mandatory and written in parentheses after the name.

Declaration Domain Typical use
x(BOOL) {0, 1} Select or skip a row
x(INT) {0, 1, 2, ...} A whole quantity
x(REAL) [0, ∞) A continuous amount

Lower bounds default to 0. A variable goes negative only when the query gives it an explicit negative bound, such as SUCH THAT adj BETWEEN -10 AND 10.

Three scopes control how many variables one declaration creates:

Spelling Scope Variables
x(INT) row-scoped (default) one per result row
T.x(INT) table-scoped one per distinct entity of T
scalar x(INT) query-wide exactly one

Table-scoped variables matter after a join: DECIDE n.keep(BOOL) gives each nurse one decision even when they appear in five shift rows.

Constraints

Operators are =, <>, <, <=, >, >=, plus BETWEEN and IN. Aggregates over a decision are SUM, AVG, MIN, and MAX. To count selected rows use SUM(x) — COUNT(x) is rejected, because a decision variable is never null and so counting one always returns the row count.

SUCH THAT SUM(x * weight) <= 50            -- aggregate
SUCH THAT x <= 3                           -- per row
SUCH THAT SUM(x) <= 2 PER category         -- one constraint per group
SUCH THAT SUM(x * cost) <= 100 WHEN region = 'EU'   -- conditional

PER produces one constraint per distinct group. WHEN is a postfix condition that restricts which rows a constraint or objective term applies to.

Objective

MAXIMIZE or MINIMIZE over an aggregate expression, or omit it entirely to ask only for a feasible assignment.

Beyond linear

Products of a decision and a column (x * weight) are linear and always supported. Two further forms work:

  • Bilinear — x * y, a product of two decisions. Bundled HiGHS handles Boolean-by-anything pairs; other pairs need Gurobi.
  • Quadratic — POWER(expr, 2), expr ** 2, or (expr) * (expr) in an objective, for least-squares style problems. Quadratic constraints are Gurobi only.

Triple products such as x * x * x are rejected.

Diagnosing a Query

Prefix any decision query with DIAGNOSE to ask why it behaved as it did — which constraints conflict when there is no answer, and what to relax.

DIAGNOSE SELECT id, x FROM Items
DECIDE x(INT) SUCH THAT x <= 5 AND x >= 8 MAXIMIZE SUM(x);

Solvers

HiGHS is embedded — nothing to install. Gurobi is detected at runtime when present and unlocks non-convex bilinear objectives and quadratic constraints.

What You Can Model

Any problem where the answer is a set of values that has to satisfy constraints while optimizing an objective — not only which rows to keep.

Problem The decision Declared as
Ship what fits in a weight budget keep or drop each row x(BOOL)
Produce how much at each plant a whole quantity per row units(INT)
Blend inputs to hit a spec at least cost a continuous amount per row mix(REAL)
Roster staff across shifts one decision per person, shared by their rows staff.on(BOOL)
Hold a portfolio under a risk limit continuous weights, quadratic risk constraint w(REAL), Gurobi
Cap the worst shortfall anywhere a single number for the whole query scalar worst(INT)

The shape is always the same: declare the decisions, constrain them, name what to optimize.

Documentation

Research

DeciDB builds on a decade of research into in-database constrained optimization:

  • Scalable Package Queries in Relational Database Systems — Brucato, Abouzied, Meliou (VLDB 2016)
  • Scalable Computation of High-Order Optimization Queries — Brucato, Abouzied, Meliou (CACM 2019)
  • Scaling Package Queries to a Billion Tuples — Mai, Wang, Abouzied, Brucato, Haas, Meliou (VLDB 2024)

License

MIT. See LICENSE.

Metadata

Release files for decidb 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for decidb 0.2.0
File Size Uploaded Provenance Actions
decidb-0.2.0.tar.gz 13.1 MB With provenance Details for decidb-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for decidb 0.2.0
File Actions
decidb-0.2.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for decidb-0.2.0-cp313-cp313-win_amd64.whl
decidb-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for decidb-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
decidb-0.2.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for decidb-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
decidb-0.2.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for decidb-0.2.0-cp312-cp312-win_amd64.whl
decidb-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for decidb-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
decidb-0.2.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for decidb-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
decidb-0.2.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for decidb-0.2.0-cp311-cp311-win_amd64.whl
decidb-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for decidb-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
decidb-0.2.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for decidb-0.2.0-cp311-cp311-macosx_11_0_arm64.whl

Total release size: 264.4 MB

Release files / decidb-0.2.0.tar.gz

Download URL decidb-0.2.0.tar.gz
Size 13.1 MB
Tags Source
SHA-256 checksum
How to use checksums
1089842857cfadf4f984e8ec70dca578e9b4ac7b0b2f7c22f57c460410fe4f6e
BLAKE2b-256 checksum
How to use checksums
d8a1df1cfb8f2a2baaf1ee5616cb5a076dd901cb06de41963e4fad80eba5d448
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / decidb-0.2.0-cp313-cp313-win_amd64.whl

Download URL decidb-0.2.0-cp313-cp313-win_amd64.whl
Size 28.0 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
6f77f3443554d0c65f50dc54d57e4a72ccc425efc0c0da52e1c4a6c67b9b8aab
BLAKE2b-256 checksum
How to use checksums
bf7d04833d5861a181303e4502e7fff40d600ddf1d81c06b0cb3613fa0493e83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / decidb-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL decidb-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 23.1 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9d81f463a588c97731d30577b50b75e6cc8b4c92fdab8045ff81bc64235446ad
BLAKE2b-256 checksum
How to use checksums
1499cdc8038dcb77428b466242b13db21361e810ecd2baf57d4922606e9ab1b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / decidb-0.2.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL decidb-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Size 32.6 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
585c8913cc3f74e89dddb6afdc430b9e5550bc22db0fcb886b9a641b13c5a4e2
BLAKE2b-256 checksum
How to use checksums
fe5587c25e74cb7fa1f2916eda40bc9f118d5a7e411079b4e51d99b3ed0a0991
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / decidb-0.2.0-cp312-cp312-win_amd64.whl

Download URL decidb-0.2.0-cp312-cp312-win_amd64.whl
Size 28.0 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
0eaebb223b276aa6f02416b6511c88b9564c01762a20e3edfaf7e71fe6b15cc9
BLAKE2b-256 checksum
How to use checksums
e01619aaa2a33f72b688335061e8a5b7838087d22d26d8c484ef475c2f31e89d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / decidb-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL decidb-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 23.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1ca0be48b382c8c64ca3c92055eaf3b1e74a70402717926af2799fdbe706c17b
BLAKE2b-256 checksum
How to use checksums
4d6cabee7cc0d0739a662e7af9e288ff6dff9935098bd5b197ff6f1b35fe0089
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / decidb-0.2.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL decidb-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Size 32.6 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3cd07429756436043c897cbab1790181b90be9cd0c4644ca1105b3c5bcee01a8
BLAKE2b-256 checksum
How to use checksums
4c6df647d2f665ab48e9ab1ef6931adf5a627badda0d80ab40bc57301af78fd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / decidb-0.2.0-cp311-cp311-win_amd64.whl

Download URL decidb-0.2.0-cp311-cp311-win_amd64.whl
Size 28.0 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
b56ee6cb27566a42113f22a968a8811242640cc4163751ad908c7f09d6229eeb
BLAKE2b-256 checksum
How to use checksums
ea0f63b327c9682fd425ab6b36876def1d505092d97741f410134c9ec0c9805e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / decidb-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL decidb-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 23.1 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
dd19f8bf8f95a925a87ea484bfc404c28f8149826ba81ad653499909ed918d58
BLAKE2b-256 checksum
How to use checksums
122665303d381418edfb0d024fae7668ee3cdf55fded37011fdda803f43764de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / decidb-0.2.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL decidb-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Size 32.6 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b89387df8ff81b2601956bb9642da5108d0c83a9cab82cb5b89475715e32db6d
BLAKE2b-256 checksum
How to use checksums
e935a6bfe35611efff3be07dd862ba7277d7da722221f5320bf2a58c477ca647
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Security for decidb 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 10 files in this release have been uploaded with provenance metadata.

Select from 10 files

Attestation for decidb-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page