Skip to content

DuckDB Extension

QuickJS

Run JavaScript expressions and functions inside DuckDB SQL with QuickJS. Pass row values as arguments or return arrays through the table function.

35,901,690
extension loads · last 90 days
On this page
Sample data for the examples

Each browser example starts with these sample tables; sample files are shared across examples on this page. Run this setup first when trying the examples in your own DuckDB session.

-- Fixtures for quickjs cookbook / technical-details / functions.json examples.
-- Small, deterministic, idempotent. Backs snippets that read from `events`
-- (raw event rows with a JSON `payload` column) and `transformed_events`
-- (the result-shaped table that holds an `extracted` JSON column).

CREATE OR REPLACE TABLE events (
    id          INTEGER,
    event_type  TEXT,
    payload     TEXT
);
INSERT INTO events VALUES
    (1, 'login',    '{"event":"login","user":"alice","meta":{"device":"phone","os":"ios"}}'),
    (2, 'purchase', '{"event":"purchase","user":"bob","amount":42.50,"meta":{"item":"book","os":"android","currency":"USD"}}'),
    (3, 'login',    '{"event":"login","user":"carol","meta":{"device":"laptop","os":"linux"}}');

CREATE OR REPLACE TABLE transformed_events (
    id         INTEGER,
    extracted  JSON
);
INSERT INTO transformed_events VALUES
    (1, '{"user":"alice","os":"ios"}'),
    (2, '{"user":"bob","os":"android"}');

Use JavaScript for a transformation inside SQL

QuickJS embeds a JavaScript engine in DuckDB. You pass SQL values to JavaScript expressions or functions and use their results in the surrounding query. A table form can turn a returned array into rows.

Use it when you already have JavaScript transformation logic or need to handle a custom structure. The embedded engine is not a Node.js process, so Node-specific modules are not automatically available. Ordinary SQL remains useful for operations DuckDB already expresses directly.

Example

Call JavaScript with SQL values

The SQL values become arguments to the JavaScript function. QuickJS returns its result as JSON.

Tested with DuckDB 1.5.6. Browser examples use Haybarn-Wasm 2.0.0-rc12.

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

WITH values_to_scale(n) AS (VALUES (3), (7))
SELECT n, quickjs_eval('(value) => value * 2', n) AS doubled
FROM values_to_scale
ORDER BY n;

Expected result

n doubled
3 6
7 14

Use DuckDB expressions for simple arithmetic in real queries. This small example shows the argument boundary for JavaScript logic that SQL does not already provide.

Common tasks

Deep Dive

Technical Details

Reference

Extension Contents

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

Configuration
quickjs_memory_limit Object type: Setting Maximum heap size of each QuickJS runtime (one per thread and query), e.g.
quickjs_timeout_ms Object type: Setting Maximum wall-clock time in milliseconds of a single QuickJS evaluation (one row of quickjs()/quickjs_eval(), or the whole quickjs table function).
Execute
quickjs() Object type: Scalar function Evaluate JavaScript code and return its completion value (the value of the last expression or statement).
quickjs_eval() Object type: Scalar function Call a JavaScript function with the given arguments and return its result as JSON.

API Reference

Function Reference

Configuration

Settings

Configure the quickjs extension behavior using these settings.

quickjs_memory_limit

Default Value: 256MB

quickjs_timeout_ms

Default Value: 0

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 Stable
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
35,901,690
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 4.55 MB
Linux aarch64 3.87 MB
macOS Apple Silicon 3.27 MB
Windows x86_64 10.71 MB
Windows x86_64 (MinGW) 18.43 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 .

Learn and explore

Tutorials and articles

Writing about QuickJS: how it works, what changed, and why.