In Week 3 of training we started learning dbt, which was interesting after spending time building our transformations straight in Snowflake. It showed us how the same kind of work can be done in a way that's much easier to manage and share, so in this blog I'll go through what dbt is, what it does for you and how it turns your SQL into tables and views using materialisations.
What is dbt?
dbt (data build tool) sits in the transformation part of the pipeline, on top of the data platform you already use, like Snowflake, Databricks or Fabric. It never stores any data itself, it just reads from and writes to your data platform, so all the data stays where it is.
It was built to solve a few common problems with transformation work. Transformation code is often hard to test and easy to break, and when the business logic is hidden away in queries that only one person understands, it becomes hard for anyone else to work on it or trust the numbers that come out of it.
What dbt does for you
- Version control: Your dbt project lives in a Git repo, like one on GitHub, so every change to your SQL is tracked, and changes can go through a pull request to be reviewed before they're merged.
- Dependencies: Instead of typing out full table names, you reference other models with the
ref()function, and dbt uses this to work out the order everything needs to run in. - Testing: You can add tests to your columns, like checking a column has no duplicates or no blanks, so bad data can be caught before it reaches a dashboard.
- Documentation: You can add descriptions to your models and columns, so anyone using them can see what each one means without having to read the SQL.
Models and what happens when you run them
In dbt, a model is just a select statement saved in a .sql file, and each model usually creates one object in your data platform, like a table or a view. When you run dbt run, dbt connects to your data platform, wraps each select statement in the SQL needed to build that object, like create table as, and then runs it in the right order.
In Snowflake, we were writing all of that create statement code ourselves, so it was useful to see dbt handle it for you. How dbt wraps your select statement is called a materialisation, and you get to choose which one each model uses.
The materialisations
- View: Stores the query, not the data, so it always shows the latest data from the tables underneath it. There's no storage cost, but the query runs every time someone uses the view, so it's only as fast as the query is. Views work well for models with light transformations, like staging models.
- Table: Stores the actual data, so it's much faster to query, but it has to be rebuilt to pick up any new data. Tables are useful for models that are queried a lot or have heavier transformations.
- Incremental: A table that, after the first run, only processes new or changed rows instead of rebuilding the whole thing. This is useful for large datasets where only a small amount of new data comes in each time, like event data.
- Ephemeral: It isn't built in your data platform at all. Instead, dbt slots its SQL into any model that references it as a CTE, which is handy for small steps that you don't need as their own object.
There's also a materialised view, which stores the result of a query like a table, but the data platform keeps it up to date for you. In Snowflake, dbt uses dynamic tables for this instead.
Setting a materialisation
You can set a materialisation for a whole folder in your dbt_project.yml file, using a + to show it's a setting rather than a folder name:
models:
my_project:
staging:
+materialized: view
marts:
+materialized: table
Or you can set it for a single model in a config block at the top of the .sql file:
{{ config(materialized='incremental') }}
Configurations are applied hierarchically, so the most specific setting wins, which means a setting on a single model overrides the setting for its folder, so you can set a default for each folder and only change the models that need something different.
After writing all the create statements and merge logic ourselves in Snowflake, it's clear why dbt has become so popular, because it takes care of how everything gets built, so you can focus on writing the select statements and deciding how each model should be materialised based on how it's going to be used.

