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 namedmodel_name.dbt run --select tag:tag_name: Runs all models tagged withtag_name.dbt run --select +model_name: Runsmodel_nameand its parents (upstream dependencies).dbt run --select model_name+: Runsmodel_nameand 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
--selectwith incorrect model names causes dbt to run zero models. - Forgetting to include dependencies with
+can cause errors if upstream models are missing. - Mixing
--selectwith--excludeincorrectly 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 dependenciesQuick Reference
| Selector | Description | Example |
|---|---|---|
| model_name | Run a specific model | dbt run --select orders |
| +model_name | Run model and its parents (upstream) | dbt run --select +orders |
| model_name+ | Run model and its children (downstream) | dbt run --select orders+ |
| tag:tag_name | Run models with a specific tag | dbt run --select tag:nightly |
| source:source_name | Run models depending on a source | dbt 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.