SQLBuild uses two syntax layers for dynamic content:Documentation Index
Fetch the complete documentation index at: https://docs.sqlbuild.com/llms.txt
Use this file to discover all available pages before exploring further.
@syntax is for any executable SQL - model queries, hooks, tests, audits, and inline source expressions${...}syntax is for config values - TOML/YAML project config, MODEL() header fields (excluding hooks), and source/seed YAML declarations
@. If it’s a config value, it uses ${...}. These layers never mix.
Syntax reference
| Syntax | Where | Resolved |
|---|---|---|
@macro(args) | Model SQL, hooks, tests, audits, inline source expressions | Compile time - expands to macro return value |
@@name | Model SQL, hooks, tests, audits, inline source expressions | Compile time - project variable substitution |
@@ENV:NAME | Model SQL, hooks, tests, audits, inline source expressions | Compile time - environment variable |
@@CTX:name | Hooks only | Compile time - target relation, environment, run ID |
@@@name | Model SQL | Preserved for runtime (custom materializations) |
@name / @'name' | Generic audit SQL only | Audit engine parameter |
${CTX:...} | TOML/YAML config values | Config compilation |
${ENV:...} | TOML/YAML config values | Config compilation |
@@CTX: is intentionally hook-only. Model SQL describes a relation’s data and should not reference its own target identity. Hooks are the operational SQL layer where target context is useful - grants, logging, post-materialization DDL.
Project variables
Project variables use@@name syntax in SQL and are defined in sqlbuild_project.toml or per-environment:
sqlbuild_local.toml for developer-specific overrides, or passed via the CLI using --vars with a JSON object:
JSON vars and nested values
--vars accepts full JSON objects. Values can be strings, numbers, booleans, null, arrays, or nested objects:
@@name), only top-level scalar values can be used directly. null renders as an empty string. If a variable resolves to an array or object, SQLBuild raises a clear error suggesting you use a macro instead.
For nested or complex values, use ctx.vars in a macro:
None.
Environment variables
Environment variables use@@ENV:NAME syntax to inject values from the shell environment:
Context variables
Context variables provide access to the current model’s target relation, environment, and run metadata. In hooks (@@CTX: syntax):
${CTX:...} syntax):
| Variable | Value |
|---|---|
target.qualified | Fully qualified target relation name |
target.schema | Target schema |
target.name | Target relation name |
model_name | Model name |
environment | Current environment name |
run_id | Current run ID |
MacroContext object is passed as the first argument when a macro function accepts a ctx parameter:
adapter_name, sqlglot_enabled, environment_name, and vars.
Deferred placeholders
Custom materializations can define runtime placeholders using@@@name syntax. These are preserved through compilation and resolved by the materialization at execution time:
Audit parameters
Generic audit SQL uses@name (single @, no parentheses) for audit-engine placeholders. These are resolved by the audit engine, not the compiler:
@@name (project variables) and @macro() (macro calls), so there is no ambiguity. See Audits for details on generic audit parameters.
Compilation order
SQLBuild processes authored SQL in this order:- Config templates (
${CTX:...},${ENV:...}) in TOML/YAML config values are resolved during config compilation - Project variables (
@@name), environment variables (@@ENV:NAME), and context variables (@@CTX:namein hooks) are substituted - Macro calls (
@name(args)) are expanded - SQLGlot validation runs against the fully expanded SQL
- Config templates resolve first, before any SQL processing
- Macros see already-substituted variable values in the SQL
@@CTX:target.qualifiedin hooks sees the final environment-overridden target name because hooks are expanded after target naming is fully resolved- SQLGlot validates the final expanded SQL, catching syntax errors from both vars and macros

