Skip to content

DuckDB Extension

Cronjob

Schedule SQL inside a running DuckDB process with cron expressions. List jobs, inspect their state, and cancel them from SQL.

56,038
extension loads Β· last 90 days
On this page
Browser execution unavailable

Cronjob's scheduler needs background threads, which this site's browser runtime does not support. Run these examples in native DuckDB or Haybarn.

Schedule SQL inside a running DuckDB process

Cronjob runs SQL repeatedly according to a cron expression. A scheduled statement can refresh a summary table, export results, or perform another task in a DuckDB process that is already running.

The schedule belongs to that process and lives in memory. Closing DuckDB removes the jobs, so this fits a persistent application or service. For a CLI command that should start on a schedule, use an external scheduler to launch DuckDB.

Example

Create, inspect, and cancel a job

Schedule a harmless query, list the job, and remove it. This example finishes before waiting for the next scheduled run.

Tested with DuckDB 1.5.6. Run this example in the DuckDB CLI or a native client.

SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
  WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL cronjob FROM query_farm;
LOAD cronjob FROM query_farm;

SET VARIABLE qf_job = (
  SELECT cron('SELECT 42', '0 * * * * *')
);
SELECT * FROM cron_jobs()
WHERE job_id = getvariable('qf_job');
SELECT cron_delete(getvariable('qf_job')) AS removed;

Jobs run only while the DuckDB process stays alive. The final statement cancels this example job; omit it only when you want the schedule to remain active.

Common tasks

Deep Dive

Technical Details

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Scheduling
cron() Object type: Scalar function Register a SQL query to run on a six-field cron expression (second minute hour day-of-month month day-of-week, evaluated in UTC).
cron_delete() Object type: Scalar function Cancel a scheduled job by job_id (the value returned from cron or visible in cron_jobs).
cron_job_history() Object type: Table function DuckDB 2.0 build only. Table function listing the most recent runs of every scheduled job β€” up to 100 per job β€” with job_id, started_at and finished_at (TIMESTAMPTZ), success (BOOLEAN) and result (Success or Error: <message>).
cron_jobs() Object type: Table function Table function listing every scheduled job in this database β€” job_id, query, schedule, next_run, status (Active/Inactive), last_run, and last_result (Success or Error: <message>).

API Reference

Function Reference

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Experimental
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
56,038
loads Β· last 90 days

Platforms

DuckDB 2.0.0

  • Linux x86_64aarch64
  • Linux (musl) Not available
  • macOS Apple Silicon
  • Windows x86_64x86_64 (MinGW)
  • WASM Not available
Compiled binary sizes
Platform Architecture Size
Linux x86_64 14.91 MB
Linux aarch64 12.60 MB
macOS Apple Silicon 11.24 MB
Windows x86_64 10.20 MB
Windows x86_64 (MinGW) 17.81 MB

Compressed download sizes for the release shown above.

DuckDB & Haybarn

Release calendar
  • DuckDB v2.0.0 Query.Farm repository Supported
  • Haybarn v1.5.6 Built-in community repository Supported

Browser examples use Haybarn-Wasm 2.0.0-rc12.

Checked .