PQL · Predictive SQL

Your data never moves. The model comes to it.

PQL is a DuckDB extension that adds TRAIN MODEL and PREDICT to SQL. No export, no pipeline, no second system.

INSTALL pql FROM community; LOAD pql;
Copied to clipboard!
  • Open source, MIT licensed
  • Runs in-process in DuckDB
  • 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 servicemust 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 whoever is already in the database.

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 run the agents

The agent

Prediction becomes a tool it already has: SQL. Score and baseline come back as rows.

Where it applies

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

SaaS renewals, e-commerce reorders, missed payments, ticket volume. 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 it cannot cheat on forecast targets.

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!

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.