dbt's node selection syntax makes it possible to run only specific resources in a given invocation of dbt. This selection syntax is used for the following subcommands:
Nodes and resources
We use the terms "nodes" and "resources" interchangeably. These encompass all the models, tests, sources, seeds, snapshots, and analyses in your project. They are the objects that make up dbt's DAG (directed acyclic graph).
dbt run executes all of the models in the dependency graph;
dbt seed creates all seeds,
dbt snapshot performs every snapshot. The
--select flag is used to specify a subset of nodes to execute.
Before dbt v0.21, certain commands (notably
compile) used a flag called
--models instead of
--select. The two were functionally identical. Those commands still support the
--models flag for backwards compatibility.
How does selection work?
dbt gathers all the resources that are matched by one or more of the
--selectcriteria, in the order of selection methods (e.g.
tag:), then graph operators (e.g.
+), then finally set operators (unions, intersections, exclusions).
The selected resources may be models, sources, seeds, snapshots, tests. (Tests can also be selected "indirectly" via their parents; see test selection examples for details.)
dbt now has a list of still-selected resources of varying types. As a final step, it tosses away any resource that does not match the resource type of the current task. (Only seeds are kept for
dbt seed, only models for
dbt run, only tests for
dbt test, and so on.)
Select resources to build (run, test, seed, snapshot) or check freshness:
dbt run will execute all of the models in the dependency graph. During development (and deployment), it is useful to specify only a subset of models to run. Use the
--select flag with
dbt run to select a subset of models to run. Note that the following arguments (
--selector) also apply to other dbt tasks, such as
--select flag accepts one or more arguments. Each argument can be one of:
- a package name
- a model name
- a fully-qualified path to a directory of models
- a selection method (
$ dbt run --select my_dbt_project_name # runs all models in your project$ dbt run --select my_dbt_model # runs a specific model$ dbt run --select path.to.my.models # runs all models in a specific directory$ dbt run --select my_package.some_model # run a specific model in a specific package$ dbt run --select tag:nightly # run models with the "nightly" tag$ dbt run --select path/to/models # run models contained in path/to/models$ dbt run --select path/to/my_model.sql # run a specific model by its path
dbt supports a shorthand language for defining subsets of nodes. This language uses the characters
# multiple arguments can be provided to --select$ dbt run --select my_first_model my_second_model# these arguments can be projects, models, directory paths, tags, or sources$ dbt run --select tag:nightly my_model finance.base.*# use methods and intersections for more complex selectors$ dbt run --select path:marts/finance,tag:nightly,config.materialized:table
As your selection logic gets more complex, and becomes unwieldly to type out as command-line arguments,
consider using a yaml selector. You can use a predefined definition with the
Note that when you're using
--selector, most other flags (namely
--exclude) will be ignored.