Render functions in the MiniJinja DuckDB extension
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 minijinja cookbook / technical-details examples.
-- Small, deterministic, idempotent (CREATE OR REPLACE).
-- "Generate HTML email per row" (cookbook) and "What you can do with one
-- query" (technical-details).
CREATE OR REPLACE TABLE users (
email TEXT,
name TEXT,
unread_count INTEGER
);
INSERT INTO users VALUES
('[email protected]', 'Alice', 3),
('[email protected]', 'Bob', 0),
('[email protected]', 'Carol', 12);
-- "Generate config files / IaC" (cookbook).
CREATE OR REPLACE TABLE virtual_hosts (
hostname TEXT,
upstream TEXT
);
INSERT INTO virtual_hosts VALUES
('app.example.com', '10.0.0.10:8080'),
('api.example.com', '10.0.0.20:9000');
Function category
Render
2 functionsRender Jinja2-compatible templates with JSON context. Supports variable substitution, filters, conditionals, for/while loops, and HTML autoescaping. The single-function surface — pass template + context, get rendered text.
Signature
Arguments
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
template
|
Type
VARCHAR
|
Mode Positional |
Description
Template source (or a template name when template_path is set).
|
Argument
autoescape
|
Type
BOOLEAN
|
Mode Named |
Description
Default: true
HTML-escape interpolated values (B&O becomes B&O). Pass false for plain text, configs, SQL or JSON output.
|
Argument
template_path
|
Type
VARCHAR
|
Mode Named |
Description
Default: ''
Directory (or a file, whose directory is used) to load templates from. When set, template is the name of a template file there, which enables {% include %} / {% extends %}. Empty means inline templates only.
|
Argument
undefined_behavior
|
Type
VARCHAR
|
Mode Named |
Description
Default: 'lenient'
How undefined variables are treated: 'lenient' renders a missing variable as empty but errors on attribute access through it, 'chainable' also renders attribute access on undefined values as empty, 'semi_strict' and 'strict' raise errors. Any other value is a binder error.
|
Argument
autoescape_extensions
|
Type
VARCHAR[]
|
Mode Named |
Description
Default: []
When non-empty, HTML autoescape applies only to templates whose name ends with one of these suffixes (for example ['.html']), overriding autoescape — useful with template_path. Must not contain NULL elements.
|
Description
Render a MiniJinja template without a JSON context. The template is the only positional argument — to supply variables, including columns or json_object built from columns, use minijinja_render_with_context. Options are keyword-only named parameters (name := value) with defaults; they must be constant expressions, unknown option names or values of the wrong type are rejected when the query is bound, and an explicit NULL option makes the result NULL.
SELECT minijinja_render('Hello World!');
SELECT minijinja_render('Hi {{ user.name }}!', undefined_behavior := 'chainable');
Signature
Arguments
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
template
|
Type
VARCHAR
|
Mode Positional |
Description
Template source (or a template name when template_path is set).
|
Argument
context
|
Type
JSON
|
Mode Positional |
Description
JSON context the template is rendered against — a literal, a JSON column, or json_object(...) built from columns.
|
Argument
autoescape
|
Type
BOOLEAN
|
Mode Named |
Description
Default: true
HTML-escape interpolated values (B&O becomes B&O). Pass false for plain text, configs, SQL or JSON output.
|
Argument
template_path
|
Type
VARCHAR
|
Mode Named |
Description
Default: ''
Directory (or a file, whose directory is used) to load templates from. When set, template is the name of a template file there, which enables {% include %} / {% extends %}. Empty means inline templates only.
|
Argument
undefined_behavior
|
Type
VARCHAR
|
Mode Named |
Description
Default: 'lenient'
How undefined variables are treated: 'lenient' renders a missing variable as empty but errors on attribute access through it, 'chainable' also renders attribute access on undefined values as empty, 'semi_strict' and 'strict' raise errors. Any other value is a binder error.
|
Argument
autoescape_extensions
|
Type
VARCHAR[]
|
Mode Named |
Description
Default: []
When non-empty, HTML autoescape applies only to templates whose name ends with one of these suffixes (for example ['.html']), overriding autoescape — useful with template_path. Must not contain NULL elements.
|
Description
Render a MiniJinja template with a JSON context, including contexts built from columns with json_object. Supports variables, filters, conditionals, for loops and autoescaping. Options are keyword-only named parameters (name := value) with defaults; they must be constant expressions, unknown option names or values of the wrong type are rejected when the query is bound, and an explicit NULL option makes the result NULL.
SELECT minijinja_render_with_context('{{ foo }}', '{"foo":"bar"}');
SELECT minijinja_render_with_context('Hello {{ user.name }}, {{ user.messages }} new', '{"user":{"name":"Alice","messages":5}}');
SELECT minijinja_render_with_context('{% for x in xs %}{{ x }}{% if not loop.last %}, {% endif %}{% endfor %}', '{"xs":["A","B","C"]}');
SELECT minijinja_render_with_context('{{ v }}', '{"v":"B&O"}', autoescape := false);