Skip to content

DuckDB Extension

Tera

Render Tera templates from DuckDB SQL using JSON context. Generate text or HTML with variables, loops, and filters, or load templates from files.

48,754
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 tera cookbook / technical-details / functions.json examples.
-- Small, deterministic, idempotent. Backs snippets that read from `users`
-- (per-row HTML email) and `virtual_hosts` (per-host config).

CREATE OR REPLACE TABLE users (
    email         TEXT,
    name          TEXT,
    unread_count  INTEGER
);
INSERT INTO users VALUES
    ('[email protected]', 'Alice',   5),
    ('[email protected]',   'Bob',     0),
    ('[email protected]', 'Carol',   2);

CREATE OR REPLACE TABLE virtual_hosts (
    hostname  TEXT,
    upstream  TEXT
);
INSERT INTO virtual_hosts VALUES
    ('a.example.com', '10.0.0.1:8080'),
    ('b.example.com', '10.0.0.2:8080'),
    ('c.example.com', '10.0.0.3:8080');

Render a template for each query row

Tera is a template language inspired by Jinja2. It uses placeholders, conditions, loops, and filters to combine a template with structured input. The DuckDB extension takes JSON context and returns the rendered text.

Use it to generate configuration files, messages, or HTML from query results, particularly when you already maintain Tera templates. SQL selects and prepares the data; the template specifies the output format. Set HTML escaping according to where the rendered string will be used.

Example

Render a greeting

Pass a JSON object as the template context. Its name field fills the template variable.

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 tera FROM query_farm;
LOAD tera FROM query_farm;

SELECT tera_render('Hello {{ name }}!', '{"name":"Mina"}') AS greeting;

Expected result

greeting
Hello Mina!

Tera and MiniJinja have similar syntax but different engines and filter support. Test existing templates before switching between them.

Common tasks

Deep Dive

Technical Details

Reference

Extension Contents

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

Configuration
tera_allow_get_env Object type: Setting Allow Tera's get_env() function to read the server's environment variables (also requires enable_external_access)
Render
tera_render() Object type: Scalar function Render a Tera template, optionally with a JSON context.

API Reference

Function Reference

Configuration

Settings

Configure the tera extension behavior using these settings.

tera_allow_get_env

Default Value: false

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 Rust
Source Available Yes
View on GitHub
Usage
48,754
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 6.30 MB
Linux aarch64 5.54 MB
macOS Apple Silicon 4.01 MB
Windows x86_64 11.38 MB
Windows x86_64 (MinGW) 20.72 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 Tera: how it works, what changed, and why.