0
0
DbtHow-ToBeginner ยท 3 min read

How to Use --select in dbt: Filter Models to Run

In dbt, use the --select flag to specify which models or resources to run by name or criteria. This lets you run only a subset of your project, speeding up builds and testing specific parts.
๐Ÿ“

Syntax

The --select flag is used with dbt commands like dbt run or dbt test to choose specific models or resources.

Basic syntax:

  • dbt run --select model_name: Runs only the model named model_name.
  • dbt run --select tag:tag_name: Runs all models tagged with tag_name.
  • dbt run --select +model_name: Runs model_name and its parents (upstream dependencies).
  • dbt run --select model_name+: Runs model_name and its children (downstream dependencies).
bash
dbt run --select <model_name_or_selector>
๐Ÿ’ป

Example

This example runs only the model named orders and its upstream dependencies.

bash
dbt run --select +orders
Output
Running with dbt=1.4.6 Found 1 model, 0 tests, 0 snapshots, 0 analyses, 0 macros, 0 operations, 0 seed files, 0 sources 17:23:45 | Concurrency: 4 threads 17:23:45 | 17:23:45 | 1 of 1 START model dbt_project.orders 17:23:47 | 1 of 1 OK created model dbt_project.orders 17:23:47 | 17:23:47 | Finished running 1 model in 2.00s.
โš ๏ธ

Common Pitfalls

  • Using --select with incorrect model names causes dbt to run zero models.
  • Forgetting to include dependencies with + can cause errors if upstream models are missing.
  • Mixing --select with --exclude incorrectly can lead to unexpected results.
bash
dbt run --select orders
# May fail if upstream models are not run first

dbt run --select +orders
# Correct: runs orders and its dependencies
๐Ÿ“Š

Quick Reference

SelectorDescriptionExample
model_nameRun a specific modeldbt run --select orders
+model_nameRun model and its parents (upstream)dbt run --select +orders
model_name+Run model and its children (downstream)dbt run --select orders+
tag:tag_nameRun models with a specific tagdbt run --select tag:nightly
source:source_nameRun models depending on a sourcedbt run --select source:raw_data
โœ…

Key Takeaways

Use --select to run specific models or groups in dbt for faster builds.
Add + before or after a model name to include upstream or downstream dependencies.
Selectors can filter by tags, sources, or model names for flexible targeting.
Always verify model names and dependencies to avoid running zero models or errors.
Combine --select with --exclude carefully to control runs precisely.