Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dbt ref() vs source()

Tags:

postgresql

dbt

I’m trying to make one model in dbt depend on another (trying to run the second model after the first one is completely finished), but I’m confused, when to use ref() or source()?

What is the difference between them?

like image 847
Sara Avatar asked Dec 06 '25 04:12

Sara


1 Answers

Using ref creates the lineage for your DAG and will run the predecessor models. Using source references a base table that is not necessarily a model. Rule of thumb is use source in your base models and everything else should use ref.

Example - Green nodes represent tables ingested into your DWH. The blue/red nodes are DBT models. enter image description here

like image 145
Adam Kipnis Avatar answered Dec 09 '25 02:12

Adam Kipnis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!