0
0
dbtdata~3 mins

Why source() function for raw tables in dbt? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could fix broken data queries by changing just one place instead of many?

The Scenario

Imagine you have many raw data tables coming from different systems. You want to use them in your data models, but you have to write full table names everywhere, and keep track of where each table lives.

The Problem

Manually typing full table names is slow and easy to mess up. If a table moves or changes, you must update every place you used it. This causes errors and wastes time.

The Solution

The source() function lets you define raw tables once and then refer to them simply. It keeps your code clean and safe from changes in table locations.

Before vs After
Before
select * from raw_database.raw_schema.customers
After
select * from {{ source('raw_database', 'customers') }}
What It Enables

You can build reliable data models that easily adapt when raw tables move or change.

Real Life Example

A data analyst uses source() to refer to sales data tables. When the data warehouse reorganizes, only the source definition changes, not all the queries.

Key Takeaways

Manually writing full raw table names is error-prone and hard to maintain.

source() centralizes raw table references for cleaner code.

This makes your data models more reliable and easier to update.