- They are only available for use in SQL, not in YML.
- They are typed (bool, int, float, string, and null)
- They are used with the
@syntax, instead of\{\{ \}\} - They can be easily set per run with the
--varsflag on CLI commands likesdf compileandsdf run
Example
In this example, we will create a variable@my_variable and use it in a SQL query.
preprocessor option to sql-vars in the workspace.sdf.yml like so:
workspace.sdf.yml
@my_variable, let’s add a vars yml block to the workspace like so:
workspace.sdf.yml
--vars flag on the CLI. For example:
@my_variable with my_value in the SQL query. The resulting query will look like this:
@my_variable with 123 in the SQL query. The resulting query will look like this:
Vars in Jinja
SQL variables can also be referenced and utilized in Jinja. For example, if we modify the query above to use jinja substitution syntax, it would look like this:vars block in the workspace.sdf.yml file like so:
workspace.sdf.yml
If you want to use both Jinja and SQL vars in preprocessing, you’ll need to set preprocessor to
all in the workspace.sdf.yml as seen above.Vars in YML
You can also set variables in avars.yml file. This is useful when you have a lot of variables to set. Here is an example of a vars.yml file:
vars.yml
--vars flag like so:
vars.yml is the path to the file.