Configuration
dbt variable interpolation
Overview
Mage allows users to reference variables specific to your pipeline or project. These variables are accessible throughout your dbt profiles, and pipelines by using the following syntax.
Syntax | Description | Example |
---|---|---|
{{ env_var('...') }} | Get from environment variables. | {{ env_var('ENV') }} |
{{ variables('...') }} | Get from runtime variables (used in YAML). | {{ variables('execution_date') }} |
{{ var('...') }} | Get from runtime variables (used in SQL). | {{ var('execution_date') }} |
DBT also comes with variable and environment variable support. By default we forward pipeline variables as dbt Project variables.
Variable interpolation examples
dbt models
dbt profiles
dbt targets
Here, we’ve used a manually entered target to specify a postgres database dependent on the environment postgres_{{ env_var('ENV') }}
.
Environment | Key | Example string | Result |
---|---|---|---|
prod | ENV | postgres_{{ env_var('ENV') }} | postgres_prod |
dev | ENV | postgres_{{ env_var('ENV') }} | postgres_dev |
Was this page helpful?