--select, or -s, accepts graph operators. A + before the model name adds everything the model
depends on, a + after it adds everything that depends on the model. With them you can rebuild one
model together with its inputs, or check what a change breaks downstream, without running the whole
project.
Copy and paste
dbt build -s customer_orders # only the model, and its tests
dbt build -s +customer_orders # the model and everything it depends on
dbt build -s customer_orders+ # the model and everything that depends on it
dbt build -s +customer_orders+ # both directions
dbt build -s 1+customer_orders # the model and its direct parents only
dbt build -s @customer_orders # the model, its children, and all their parents
dbt ls -s +customer_orders # list the selection without running anything
What each operator selects
In the example project two staging views read the raw tables, customer_orders joins them, and
revenue_by_country reads customer_orders and stg_customers:
| Selector | Selects |
|---|---|
customer_orders |
customer_orders |
+customer_orders |
stg_customers, stg_orders, customer_orders |
customer_orders+ |
customer_orders, revenue_by_country |
+customer_orders+ |
the four models above |
1+revenue_by_country |
customer_orders, stg_customers, revenue_by_country |
@customer_orders |
customer_orders, revenue_by_country, stg_customers, stg_orders |
A number sets the depth: 1+customer_orders stops at the direct parents, customer_orders+2 at the
children of the children.
@ adds the children and then every parent of those children, which is what you need to build
revenue_by_country correctly after changing customer_orders.
Check the selection first
dbt ls prints what a selector picks without touching the warehouse:
dbt ls -s +customer_orders --resource-type model
shop.marts.customer_orders
shop.staging.stg_customers
shop.staging.stg_orders
Without --resource-type, the list also includes the sources (source:shop.raw.orders) and the tests
of the selected models.
run, build or test
dbt runbuilds only the models.dbt buildbuilds models, seeds and snapshots and runs their tests, in dependency order. When a test fails, the models after it are skipped, so bad data does not travel downstream.dbt test -s +customer_ordersruns only the tests.
Sources are never built: they are tables already in the warehouse. Ephemeral models are not built either, because dbt compiles them into the models that use them.
Combining selectors
- Union. Separate selectors with spaces:
-s +customer_orders revenue_by_country. - Intersection. Join them with a comma:
-s marts,tag:dailyselects the models that are in themartsfolder and have thedailytag. - Folders and tags.
-s martsselects a folder,-s tag:dailya tag, and both accept the graph operators:-s +tag:daily. - Exclusions.
--excluderemoves nodes from the selection; see how to exclude a folder or a tag.
Tested with dbt Core 1.12.