Search code examples
dbt

Exclude multiple models from run


When running dbt with descendants, I would like to exclude two models. I can exclude one model like so:

dbt run ga4_update_set+ --exclude nz_daily_cohorts

The above works as expected.

I tried the following to exclude multiple models.

dbt run ga4_update_set+ --exclude nz_daily_cohorts,growth_scorecard

In this case neither nz_daily_cohorts nor growth_scorecard were excluded.

Then tried:

dbt run ga4_update_set+ --exclude nz_daily_cohorts --exclude growth_scorecard

Again, in this case neither nz_daily_cohorts nor growth_scorecard were excluded.

How can I run dbt run ga4_update_set+ but also exclude both nz_daily_cohorts and growth_scorecard?


Solution

  • The easiest solution is to just space-delimit your exclude list instead of comma-delimiting

    dbt run ga4_update_set+ --exclude nz_daily_cohorts growth_scorecard

    If you need to repeat this job, it may be more convenient to create a selector:

    selectors:
      - name: custom_job
        definition:
          union:
            - method: fqn
              value: ga4_update_set
              children: true
            - exclude:
                - method: fqn
                  value: nz_daily_cohorts
                - method: fqn
                  value: growth_scorecard
    

    Then run your command with dbt run --selector custom_job