Methods

Selector methods allow you to filter resources based on specific properties using the method:value syntax. While it's advisable to explicitly denote the method, you can omit it, and the default will be one of path, file, or fqn.

Most selector methods below support unix-style wildcards:

WildcardDescriptionExample

*

matches any number of characters (including none)

dbt list --select "*.folder_name.*"

?

matches any single character

dbt list --select "model_?.sql"

[abc]

matches one character listed in the bracket

dbt list --select "model_[abc].sql"

[a-z]

matches one character from the specified range in the bracket

dbt list --select "model_[a-z].sql"

Below are examples of several popular selector methods:

"tag" Method

Use the tag: method select models with a specified tag.

dbt run --select "tag:hourly"    
# Run all models with the 'hourly' tag

"source" Method

Use the source: method to select models that reference a specified source.

dbt run --select "source:fivetran+"  
# Runs all models that reference the fivetran source

"resource_type" method

Use the resource_type method to select nodes of a specific type (ex. model, test, exposure, etc.)

dbt run --select "resource_type:exposure"  
# Runs all models and tasks related to exposures
dbt list --select "resource_type:test"  
# Lists all tests in your project

"Path" method

Use path method to select models/sources defined at or under a specific path.

dbt run --select "path:models/marts"
# Runs all models in the "models/marts" path
dbt run --select "path:models/marts/customers.sql"
# Runs a specific model, "customers.sql", in the "models/marts" path. 

"file" method

Use file method to select a model by filename.

dbt run --select "file:model_name.sql"
# Runs the model defined in 'model_name.sql'

# Note: Adding the file extension (e.g., ".sql") is optional.
dbt run --select "file:model_name"

"fqn" method

Use 'fqn' to select nodes based off their "fully qualified name" (FQN). The default FQM format includes the dbt project name, subdirectories, and the file name

dbt run --select "fqn:example_model"
# Runs the model named 'example_model'

dbt run --select "fqn:project_name.example_model"
# Runs the model 'model_one' in 'example_model'

dbt run --select "fqn:package_name.example_model"
# Runs 'example_model' in 'package_name'

dbt run --select "fqn:example_path.example_model"
# Runs 'example_model' in 'example_path'

dbt run --select "fqn:project_name.example_path.example_model"
# Runs 'example_model' in 'example_path' within 'project_name'

"package" method

Use package method to select models defined within the root project or an installed dbt package.

dbt run --select "package:fivetran"
# Runs all models in the 'fivetran' package

# Note: Adding "package" prefix is optional. The following commands are equivalent:
dbt run --select "fivetran"
dbt run --select "fivetran.*"

"Config" method

Use config to select models that match a specified node config.

dbt run --select "config.materialized:table"
# Runs all models that are materialized as tables

dbt run --select "config.schema:staging"
# Runs all models that are created in the 'stagins' schema

dbt run --select "config.cluster_by:zip_code"
# Runs all models clustered by 'zip_code'

Note: config method work for non-string values, such as: booleans, dictionary keys, values in arrays, etc.

Suppose you have a model with the following configurations:

{{ config(
  materialized = 'view',
  unique_key = ['customer_id', 'order_id'],
  grants = {'insert': ['sales_team', 'marketing_team']},
  transient = false
) }}

select ...

You can use config method to select the following:

dbt ls -s config.materialized:view
# Lists all models materialized as views

dbt ls -s config.unique_key:customer_id
# Lists all models with 'customer_id' as a unique key

dbt ls -s config.grants.insert:sales_team
# Lists all models with insert grants for the sales team

dbt ls -s config.transient:false
# Lists all models that are not transient

"test_type" method

Use test_type to select tests based on type (singular or generic)

dbt test --select "test_type:generic"
# Runs all generic tests

dbt test --select "test_type:singular"
# Runs all singular tests

"test_name" method

Use test_name method to select tests based on the name of the test defined.

dbt test --select "test_name:not null"
# Runs all instances of the 'not null' test

dbt test --select "test_name:not_accepted_values"
# Runs all instances of the 'dbt_utils.not_accepted_values' test

"exposure" method

Use exposure method to select the parent resources of an exposure.

dbt test --select "exposure:monthly_reports" 
# tests all models that feed into the monthly_reports exposure

dbt run --select "+exposure:*"           
# Runs all upstream resources of all exposures

dbt ls --select "+exposure:*" --resource-type model  
# Lists all upstream models of all exposures

"metric" method

Use metric method to select parent resources of a metric.

dbt run --select "+metric:monthly_qualified_leads"
# Runs all upstream resources of the monthly_qualified_leads metric

dbt build --select "+metric:*" --resource-type model
# Builds all upstream models of all metrics

"results" method

Use result method to select resources based on their results status from a previous execution.

dbt run --select "result:success" --state path/to/project/artifacts
# Runs all models that successfully ran on the previous execution of dbt run

dbt test --select "result:warn" --state /path/to/project/artifacts
# Runs all tests that issued warnings on the previous execution of dbt test

dbt seed --select "result:fail" --state /path/to/project/artifacts
# Runs all seeds that failed on the previous execution of dbt seed

Note: This method only works if a dbt command (ex. seed, test, run, build.) was performed prior.

"group" method

Use group method to select models defined within a specified group.

dbt run --select "group:marketing"
# Runs all models that belong to the marketing group

"access" Method

Use access method to select models based on their access property.

dbt list --select "access:public"
# List all public models

"version" Method

Use version to select versioned models based on the following:

  • Version Identifier: A specific version label or number (old, prerelease, latest)

  • Latest Version: The most recent version of a model.

dbt list --select "version:old"  
# lists versios older than the 'latest' version

dbt list --select "version:prerelease"  
# Lists versions new than the 'latest' version. 

dbt list --select "version:latest"  
# lists the 'latest'version

"semantic_model" Method

Use semantic_model method to selects semantic models.

dbt run --select "semantic_model:sales"  
# Runs the semantic model named "sales" and all its dependencies

dbt build --select "+semantic_model:customer_orders"  
# Builds the semantic model "customer_orders", as well as all upstream resources

dbt ls --select "semantic_model:*"  
# Lists all resources semantic models

"saved_query" method

Use saved_query method to selects saved queries.

dbt list --select "saved_query:*"                    
# Lists all saved queries 
dbt list --select "+saved_query:customers_queries"  
# Lists your saved query named "customers_queries" and all upstream resources

Last updated