dbt using variable to make your sql more flexible
dbt uses jinja as a template engine to work with file. Therefor we can configure our variable 2 ways.
1. dbt_project.yaml or vars.yml (on the project root) - we can introduce variable by using the followings - as you can see here we are introducing a variable call person.
this is what your vars.yml looks like
2. passing variable in from the command line using --var argument. Please note variable are passed in as json - so we need to do something like this. Please note: it is important to use double quote for variable name, otherwise you won't be able to pass it in.
Plese refer to variable precedence for additional guide here.
dbt run --vars '{"sold_date_sk": 20000, "person": "JohnDoe"}'
And this is what our template looks like where we have our "sold_date_dk". This is for illustration purpose only.
And you can see that dbt has compile it as such
When we passed in the followings
dbt run --vars '{"sold_date_sk": 10000, "person": "JohnDoe2"}'
Noticed that sql statement gets udpated accordinly.
Comments