How to Use dbt run: Syntax, Example, and Tips
Use the
dbt run command to compile and execute your dbt models, transforming raw data into clean tables. Run it in your project directory to build all models or specify particular models with flags like --select.Syntax
The basic syntax of dbt run is simple. You run it in your dbt project folder to build models.
dbt run: Runs all models in the project.--select model_name: Runs only the specified model(s).--exclude model_name: Skips specified model(s).--modelsis an alias for--select.
bash
dbt run [--select model_name] [--exclude model_name]
Example
This example shows how to run all models and then run only a specific model named customers.
bash
cd my_dbt_project
# Run all models
dbt run
# Run only the 'customers' model
dbt run --select customersOutput
Running with dbt=1.4.6
Found 5 models, 0 tests, 0 snapshots, 0 analyses, 0 macros, 0 operations, 0 seed files, 0 sources
Running 5 models:
1 of 5 START table model my_dbt_project.customers................ [RUN]
1 of 5 OK created table model my_dbt_project.customers........... [OK in 1.2s]
...
Finished running 5 models in 12.3s.
Running with dbt=1.4.6
Found 5 models, 0 tests, 0 snapshots, 0 analyses, 0 macros, 0 operations, 0 seed files, 0 sources
Running 1 model:
1 of 1 START table model my_dbt_project.customers................ [RUN]
1 of 1 OK created table model my_dbt_project.customers........... [OK in 1.1s]
Finished running 1 model in 1.1s.
Common Pitfalls
Some common mistakes when using dbt run include:
- Running
dbt runoutside the project directory causes errors because dbt can't find your project files. - Not specifying models when you want to run only a subset can lead to long run times.
- Using outdated model names or typos in
--selectcauses dbt to skip models silently. - Not having your profiles.yml configured properly leads to connection errors.
bash
## Wrong: running outside project folder $ dbt run # Error: Could not find dbt_project.yml ## Right: change to project folder first $ cd my_dbt_project $ dbt run
Quick Reference
| Command | Description |
|---|---|
| dbt run | Builds all models in the project |
| dbt run --select model_name | Builds only the specified model(s) |
| dbt run --exclude model_name | Builds all models except the specified ones |
| cd project_folder | Navigate to your dbt project directory before running commands |
Key Takeaways
Run
dbt run inside your dbt project folder to build models.Use
--select to run specific models and save time.Check your profiles.yml to ensure database connection is configured.
Avoid typos in model names when using selection flags.
Running
dbt run compiles and executes SQL models to create tables or views.