0
0
DbtHow-ToBeginner ยท 3 min read

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 --exclude flag.
  • Using --exclude without --select runs all models except excluded ones, which might be unintended.
  • Confusing --exclude with --select can 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

FlagDescriptionExample
--excludeSkip specified models during command executiondbt run --exclude customers orders
--selectRun only specified modelsdbt run --select customers
Model nameSpecify a single model by namecustomers
Tag selectorExclude models by tagtag:nightly
Multiple modelsExclude multiple models separated by spacecustomers 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.