Skip to content

Commit 3a37590

Browse files
authored
Docs: add predefined macro vars to jinja macros page (#3766)
1 parent 3b945d1 commit 3a37590

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

docs/concepts/macros/jinja_macros.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,30 @@ JINJA_STATEMENT_BEGIN;
5050
JINJA_END;
5151
```
5252

53+
## SQLMesh predefined variables
54+
55+
SQLMesh provides multiple [predefined macro variables](./macro_variables.md) you may reference in jinja code.
56+
57+
Some predefined variables provide information about the SQLMesh project itself, like the [`runtime_stage`](./macro_variables.md#runtime-variables) and [`this_model`](./macro_variables.md#runtime-variables) variables.
58+
59+
Other predefined variables are [temporal](./macro_variables.md#temporal-variables), like `start_ds` and `execution_date`. They are used to build incremental model queries and are only available in incremental model kinds.
60+
61+
Access predefined macro variables by passing their unquoted name in curly braces. For example, this demonstrates how to access the `start_ds` and `end_ds` variables:
62+
63+
```sql linenums="1"
64+
JINJA_QUERY_BEGIN;
65+
66+
SELECT *
67+
FROM table
68+
WHERE time_column BETWEEN '{{ start_ds }}' and '{{ end_ds }}';
69+
70+
JINJA_END;
71+
```
72+
73+
Because the two macro variables return string values, we must surround the curly braces with single quotes `'`. Other macro variables, such as `start_epoch`, return numeric values and do not require the single quotes.
74+
75+
Unlike other predefined macro variables, the `gateway` variable name cannot be unquoted. Instead, it must use the `{{ var() }}` function like [user-defined variables](#global-variables) do: `{{ var('gateway') }}`.
76+
5377
## User-defined variables
5478

5579
SQLMesh supports two kinds of user-defined macro variables: global and local.

0 commit comments

Comments
 (0)