📘 Introduction

In this hands-on dbt tutorial, you'll learn how to overwrite project variables at runtime — a powerful feature that lets you dynamically change your dbt model behavior without modifying your code or dbt_project.yml. This is especially useful when you need to run the same transformation logic in different environments (e.g., dev, staging, prod) or with different parameter values.

✅ Prerequisites

☑️ A dbt project set up
☑️ Set up Medallion Architecture
☑️ Source data loaded into your data warehouse
☑️ Source configurations defined in sources.yml

💡 What Does “Overwriting Variables at Runtime” Mean?

In dbt, you can define variables under the vars section of your dbt_project.yml file. However, these values are not fixed— dbt allows you to overwrite them during runtime using the --vars flag in your CLI commands.

This means you can dynamically change the behavior of your SQL models without editing project files, which is perfect for parameterized runs, environment-specific configurations, or experimentation.

🧠 Practical Example

Let’s continue with the example from our previous post:

Getting Started with Project Variables in dbt: A Hands-On Introduction
📘 Introduction In this hands-on dbt tutorial, you’ll learn how to use project variables to make your SQL models more dynamic, flexible, and reusable. Instead of hardcoding values directly into your SQL logic, dbt allows you to define variables in your dbt_project.yml file. These variables can be adjusted at

In this example the table dim_course contains the following data:

We filtered the courses in dim_course based on their number of credits using a project variable:

vars:
  credits_threshold: 20

Our dbt model course_analytics.sql uses this variable in the WHERE clause:

SELECT
  id,
  code,
  name,
  credits,
  level,
  semester_number,
  source_name
FROM {{ ref('dim_course') }}
WHERE credits < {{ var('credits_threshold') }}

Now, instead of updating the threshold value in dbt_project.yml, we’ll overwrite it at runtime.

🚀1️⃣ Run dbt model with a different variable value

You can overwrite the variable using the --vars flag directly in the dbt run command:

You can view this post with the tier: Academy Membership

Join academy now to read the post and get access to the full library of premium posts for academy members only.

Join Academy Already have an account? Sign In