How to Use --exclude Flag in dbt to Skip Models
In dbt, use the
--exclude flag to skip specific models when running commands like dbt run or dbt test. Provide model names or selectors after --exclude to exclude them from execution.Syntax
The --exclude flag is used with dbt commands to skip one or more models during execution.
Basic syntax:
dbt run --exclude model_name- skips a single model.dbt run --exclude model1 model2- skips multiple models.dbt run --exclude tag:tag_name- skips all models with a specific tag.
You can combine --exclude with --select to control exactly which models run.
bash
dbt run --exclude <model_name_or_selector> [<additional_models_or_selectors>]
Example
This example shows how to run all models except one named customers.
bash
dbt run --exclude customers
Output
Running with dbt=1.4.0
Found 10 models, excluding 1 model: customers
17:00:00 | Concurrency: 4 threads
17:00:00 |
17:00:00 | 9 of 9 START table model project.orders................ [RUN]
17:00:10 | 9 of 9 OK created table model project.orders........... [SUCCESS 10s]
Completed successfully
Common Pitfalls
- Not specifying the exact model name or selector causes dbt to ignore the
--excludeflag. - Using
--excludewithout--selectruns all models except excluded ones, which might be unintended. - Confusing
--excludewith--selectcan lead to running wrong models. - Forgetting to separate multiple models with spaces after
--exclude.
Example of wrong usage:
dbt run --exclude=customers
Correct usage:
dbt run --exclude customers
Quick Reference
| Flag | Description | Example |
|---|---|---|
| --exclude | Skip specified models during command execution | dbt run --exclude customers orders |
| --select | Run only specified models | dbt run --select customers |
| Model name | Specify a single model by name | customers |
| Tag selector | Exclude models by tag | tag:nightly |
| Multiple models | Exclude multiple models separated by space | customers orders |
Key Takeaways
Use
--exclude to skip specific models during dbt runs or tests.Separate multiple models with spaces after
--exclude without using equals sign.Combine
--exclude with --select for precise model control.Ensure model names or selectors are correct to avoid unexpected runs.
Use tags with
--exclude to skip groups of models easily.