SQL Templates
Write a template once and run it against different tables or values without copying.
Quick start
- Run normally (
Mod+Enter/ toolbar ▶). The backend reads@vars, finds{{ schema }}and{{ table }}, expands each combination, and opens a result tab for each row. - Missing variables — If a placeholder has no value yet, a dialog pops up to fill in one value per line. Check "Save values as @vars comment above SQL" to write the filled values back as a
@varsblock — next run needs no dialog. - Toolbar
{}button — Select SQL, click{}in the toolbar to auto-generate an@varsscaffold for all{{ name }}placeholders found in the selection. Fill in values directly in the editor.
Examples
Single variable — batch across tables
→ 3 result tabs: count of customers, orders, products.
Multiple variables — cartesian product
With table_prefix set to sales in the dialog, this expands to 2 SQLs (public.sales_us, public.sales_eu), each producing one result tab.
Date range in WHERE
Column names in aggregation
Syntax
How it works
- Backend (Rust + minijinja): parses the
@varsYAML block, renders the Jinja template withUndefinedBehavior::StrictandAutoEscape::None, and performs a cartesian product when several variables have multiple values (max 50 combinations). - Frontend (TypeScript): pure helpers (
src/lib/sql/macros.ts) for formatting YAML blocks, merging dialog overrides, and building empty scaffolds. - No effect on existing SQL without
{{ }}placeholders.
Batch execution
When a variable has multiple values (YAML list or multi-line in dialog), the system generates one statement per combination and opens a result tab for each. All tabs execute in parallel. A soft limit (20) asks for confirmation; a hard limit (50) rejects.

