Materializations
The same model SELECT can become a view, a table, an incremental table or an ephemeral snippet. That choice, the materialization, decides cost and speed. This lesson shows what each one does and when to pick it.
Pipelines in production · dbt · Bronze · Building models, lesson 3 of 4
On this page
Read first: ref() and the DAG (skip if you know it)
In plain words first
A recipe can be served as a fresh dish cooked on every order (a view), a batch cooked once and kept in the fridge (a table), a batch topped up each day with only the new portions (incremental), or a sauce folded straight into another dish (ephemeral). Same recipe, different way of serving it.
Same SELECT, different DDL
The materialization decides what dbt does with a modelmodel: A SELECT statement in a .sql file. dbt runs it and saves the result in the warehouse as a table or view named after the file. Learn more →'s SELECT. The model code does not change; only the wrapping does.
| Materialization | What dbt runs | Query cost | Build cost |
|---|---|---|---|
| view (default) | create or replace view x as (select ...) | Runs the SELECT every time someone queries it | Almost none |
| table | create or replace table x as (select ...) | Reads stored rows: fast | Recomputes everything every run |
| incremental | First run: create table. Later runs: insert or merge only new rows | Fast | Only the new data |
| ephemeral | Nothing. The SELECT is inlined as a CTE into the models that ref it | Paid by each child | None |
| materialized_view | create materialized view; the warehousewarehouse: A database built for analytics on large tables, like Snowflake, BigQuery, Databricks or Redshift. dbt runs its SQL there. Learn more → refreshes it | Fast | Refresh managed by the warehouse |
Configuring it
{{ config(materialized='table', tags=['finance']) }} select ...
models:
- name: fct_invoices
config:
materialized: table
Or for a whole folder with +materialized in dbt_project.yml. The config in the model file wins over YAML, which wins over the project file.
Choosing
- 1Start with a view. Staging modelsstaging model: The first layer of models: one per source table, renaming and casting columns, with no joins or business logic. Learn more → are thin and read rarely on their own, so views cost nothing to build and are never stale.
- 2Make it a table when people or BI tools query it, or when many models read it: computing once beats computing on every read.
- 3Make it incremental when rebuilding the table takes too long or costs too much, typically large event or fact tables. It adds complexity (see Incremental modelsincremental model: A model that, after its first build, only processes new or changed rows and merges them into the existing table. Learn more →), so it is not the default.
- 4Use ephemeral for small helper steps you do not want in the warehouse. Not for anything you want to query or debug directly.
Ephemeral, inlined
select * from {{ ref('int_invoice_charges') }} -- an ephemeral model
Compiles to
with __dbt__cte__int_invoice_charges as ( select invoice_id, sum(amount) as charged from analytics.dbt_alice.stg_charges group by 1 ) select * from __dbt__cte__int_invoice_charges
Because an ephemeral model never exists in the warehouse, you cannot query it while debugging, and if five models ref it, its SQL runs five times. Keep ephemeral models small.
Materialized views
Supported on Snowflake (dynamic tables), BigQuery, Databricks, Redshift and Postgres. dbt creates the object; the warehouse keeps it up to date. Useful for near-real-time marts with simple SQL. The limits come from the platform: some SQL is not allowed in materialized views, refresh costs are paid even when nobody reads, and dbt cannot run custom logic per refresh as it can with incremental models.
How a table rebuild stays safe
On warehouses without atomic create or replace, dbt builds the new table under a temporary name, then renames: the old version stays readable until the swap, and a failed build leaves the old table untouched. Readers never see a half-built table.
Common mistakes
- Making everything a table — Every run rebuilds every table. Staging as views is usually enough.
- Long chains of views under dashboards — Every dashboard query recomputes the whole chain.
- Big ephemeral models referenced many times — Their SQL is inlined and executed once per child.
Key takeaways
- A materialization only changes the DDL around the same SELECT.
- Views cost nothing to build but recompute on read; tables are the reverse.
- Incremental models trade simplicity for build time on large tables.
- Ephemeral models are inlined as CTEs and cannot be queried directly.
Interview prep
THE QUESTION
"When would you choose a view, a table or an incremental model in dbt?"
Avoid: "always use tables because they are faster". Tables rebuild fully each run; views and incremental models exist for good reasons.
Follow-ups · answer out loud, then open
Follow-up"What exactly is an ephemeral model?"
Scenario"A dashboard on a dbt mart is slow, and the mart is a view over three other views. What do you change?"
Trap"A materialized view is the same as an incremental model."
Check yourself
3 questionsWhat is the default materialization in dbt?
Show the answer
view. Models are views unless configured otherwise.
An ephemeral model is referenced by four models. How many times does its SQL run during dbt run?
Show the answer
Four times, once inlined in each child. It is inlined as a CTE into each model that refs it.
A 3 TB plays table takes two hours to rebuild nightly. Which materialization fits?
Show the answer
incremental. Process only new plays each run.
Practise this
Problems that use this, graded on hidden tests
Keep going
Up next · Building models · lesson 4 of 4 · 5 min readData tests
unique, not_null, accepted_values and relationships, singular tests, and how a test fails: it returns rows.
Related lessons
Incremental modelsdbt · 5 min read
A dbt project, file by filedbt · 5 min read
ref() and the DAG
Previous: ref() and the DAG
Primary sources: Materializations