Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Macros
Macros are snippets of SQL that can be called like functions in models. Macros make it possible to re-use SQL between models in keeping with the engineering principle of DRY (Don't Repeat Yourself). Moreover, packages can expose Macros that you can use in your own dbt project.
To use macros, add a
macro-paths
config entry to yourdbt_project.yml
file. Macro files must use the.sql
file extension.Macro files can contain one or more macros. An example macro file looks like:
Here, we define a macro called
times_two
which takes a single argument, n. A model which uses this macro might look like:which would be compiled to:
In the above example, we could reference the macro directly because it lives in our own project. If the macro was imported from the
dbt_math_macros
package via:then we would need to fully-qualify the macro:
Here,
dbt_math_macros
is both the name of the repository, and thename
specified in the (fictional) repo'sdbt_project.yml
file.