PQL · Predictive SQL32,560 downloads

One line of SQL. A real prediction model.

PQL adds TRAIN MODEL and PREDICT to DuckDB. Your agents answer “what happens next?” in the SQL they already speak. No pipeline, no export, no second system.

INSTALL pql FROM community; LOAD pql;
Copied to clipboard!
  • Open source, MIT licensed
  • Runs inside DuckDB, in-process
  • Trains in seconds on a laptop CPU
TRAIN MODEL lapse
  PREDICT EXISTS(transactions)
  FOR customers AT last_seen_at
  HORIZON 30 DAYS;

-- seconds later: score, baseline

PREDICT EXISTS(transactions)
  FOR customers USING MODEL lapse;
What it is

The usual path moves your data. PQL moves the model.

Today: the data leaves
  • 8 steps
  • 3 tools
  • 2 teams
  • weeks
Your databasetables, keys, history
Exporta copy leaves
Feature pipelinehand-written
Training stackPython, GPU
Serving layermust stay in sync
With PQL: the model comes to the data
  • 1 statement
  • seconds
Your databaseDuckDB, with the PQL extension loadednothing is exported, nothing is copied
your tablesas they are
TRAIN MODELfeatures built from the keys
PREDICTone row per entity
Who it is for

Built for everyone already in the database. Humans and agents.

If you own the database

The database developer

One SQL statement, same tables, same permissions. Nothing to deploy.

If you build the models

The data scientist

A first defensible model in seconds, not weeks. Leakage handled by construction.

If you are an agent

The AI agent

Trains, scores and predicts on its own, in the SQL it already writes. No Python and no training stack to hand it.

Where it applies

An entity, its events, and a question about its future.

SaaS renewals, e-commerce reorders, missed payments, support tickets: the shape is always the same.

Restaurants and hospitality

customer_idcustomersthe entitylocationsbranchtransactionsone per visitline_itemswhat was orderedproductsmenu item

Which regulars are about to stop coming?

TRAIN MODEL lapse
  PREDICT EXISTS(transactions)
  FOR customers AT last_seen_at
  HORIZON 30 DAYS;

Tracking, logistics and fleet

shipment_idcarrier_idvehicle_idscan_eventstracking scansmaintenanceservice logdeliveriesoutcomeshipmentsthe entitycarriersvehiclesa second entity

Will this shipment hit an exception in the next three days?

TRAIN MODEL risk
  PREDICT EXISTS(scan_events
  WHERE scan_events.type = 'exception')
  FOR shipments AT dispatched_at
  HORIZON 3 DAYS;
More examples in the tutorial
Leakage, handled by construction

Why a forecast cannot cheat.

PQL splits time at each row's AT value. Features come only from before it, and the engine counts the label after it.

everything the model may look athistory from every related table
anchor: this row's AT time
what it is asked to predictthe HORIZON window
later rows, never seen
time
Proof on RelBench

The same accuracy class, from one statement.

RelBench is the Stanford benchmark for relational prediction.

rel-f1 taskPQLGradient boostingBoostinghand-built featuresGraph neural netGNNRelBench RDL, GPU
Qualify top-3 next month?AUROC0.8090.8420.809
Fail to finish a race?AUROC0.7070.7010.741
Finishing position?MAE, lower is better4.1234.4034.259
Hardware, training timeLaptop CPU
3 to 15 s
Laptop CPU
about 1 s
NVIDIA L4 GPU
17 to 78 s

One win, one tie, one loss against each, without moving a row.

Written by hand
PQL
1 statement
Gradient boosting
126 lines of feature SQL
Graph neural net
~120 lines of model code

Try it in two minutes.

Load the extension in any DuckDB shell and train your first model on the tables you already have.

INSTALL pql FROM community; LOAD pql;
Copied to clipboard!
32,560 downloads

Frequently Asked Questions

PQL (Predictive SQL) is an open-source DuckDB extension that adds TRAIN MODEL and PREDICT to SQL. It trains a model on the tables you already have, builds features from your foreign keys, and returns predictions as rows, like any query.

TRAIN reports a score on rows the model never saw, next to a baseline: the answer you would get with no model at all. If the model does not beat the baseline, you see it immediately.

Single-series and seasonal forecasting, such as total daily revenue for one branch. A dedicated time-series model does better there. PQL is built for questions about many entities with related, timestamped events.

Not today, by design. Models live for the session. TRAIN and PREDICT run in the same job, in seconds, so every prediction is on fresh data. Persistence is on the roadmap for cases that need a frozen model.

Yes. PQL is MIT licensed and developed in the open at github.com/Guepard-Corp/duckdb-pql.