--exclude takes the same selectors as --select and removes what they match. It is the quickest way
to skip a slow folder, a set of models that belong to another team, or models that are not ready yet.
Copy and paste
dbt build --exclude tag:finance # everything except the models tagged finance
dbt build --exclude path:models/marts/finance # everything except one folder
dbt build --exclude marts.finance # the same folder, by its place in the project
dbt build -s marts --exclude tag:finance # one folder, minus a tag
dbt build --exclude tag:finance tag:slow # several exclusions: anything matching either
Tag a model in its file:
{{ config(tags=['finance']) }}
Or a whole folder in dbt_project.yml:
models:
shop:
marts:
finance:
+tags: finance
Check what remains
dbt ls -s marts --exclude tag:finance --resource-type model
shop.marts.customer_orders
shop.marts.fct_orders
shop.marts.orders_daily
shop.marts.shipped_revenue
revenue_by_country, the only model tagged finance, is gone.
How exclusions behave
- Exclusion wins. dbt applies
--selectfirst and--excludesecond, so a node that matches both is excluded. - Tests follow their model. The tests of an excluded model are excluded as well: a
not_nulltest onrevenue_by_countrydisappears from the run without being tagged itself. - Graph operators work here too.
--exclude tag:finance+also removes everything downstream of the finance models. - Exclusion is not a dependency check. If a model you keep reads from an excluded one, dbt does not rebuild the excluded model; it reads whatever table already exists.
Save it as a selector
An exclusion you use every night belongs in selectors.yml, at the root of the project:
selectors:
- name: nightly
definition:
union:
- method: path
value: models
- exclude:
- method: tag
value: finance
dbt build --selector nightly
Tested with dbt Core 1.12.