Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Seeds for Static Reference Data in dbt
📖 Scenario: You are working on a data project where you need to use static reference data, like country codes and names, inside your dbt models. Instead of hardcoding these values in SQL, you will use dbt seeds to manage this static data easily and keep your project organized.
🎯 Goal: Learn how to create a seed file in dbt, configure it, use it in a model, and finally query the seeded data to see the results.
📋 What You'll Learn
Create a CSV seed file with country codes and names
Configure dbt to recognize the seed file
Write a dbt model that selects from the seed data
Run dbt commands to load and query the seed data
💡 Why This Matters
🌍 Real World
Static reference data like country codes, product categories, or status lists are common in data projects. Using dbt seeds helps keep this data organized and version controlled.
💼 Career
Data analysts and engineers often need to manage static data efficiently. Knowing how to use dbt seeds is a valuable skill for building maintainable data pipelines.
Progress0 / 4 steps
1
Create the seed CSV file
Create a CSV file named countries.csv inside the data folder of your dbt project. The file should have two columns: country_code and country_name. Add these exact rows: country_code,country_name US,United States CA,Canada MX,Mexico
dbt
Hint
Make sure the file is named exactly countries.csv and placed inside the data folder.
2
Configure dbt to load the seed file
In your dbt_project.yml file, add or update the seeds section to include your project name and set quote_columns to false. For example, if your project is named my_dbt_project, add: seeds: my_dbt_project: quote_columns: false
dbt
Hint
Replace my_dbt_project with your actual dbt project name exactly.
3
Create a dbt model to select from the seed data
Create a new model file named country_list.sql inside the models folder. Write a SQL query that selects all columns from the seed table countries. Use the exact code: select * from {{ ref('countries') }}
dbt
Hint
Use the ref function to refer to the seed table named countries.
4
Run dbt seed and query the model output
Run the command dbt seed to load the seed data into your warehouse. Then run dbt run to build the model. Finally, query the model country_list in your warehouse to see the output. Print the results showing the country codes and names exactly as: US | United States CA | Canada MX | Mexico
dbt
Hint
Make sure to run dbt seed before dbt run to load the seed data.
Practice
(1/5)
1. What is the main purpose of using seeds in dbt?
easy
A. To create dynamic tables based on SQL queries
B. To load static reference data from CSV files into your database
C. To schedule dbt runs automatically
D. To write Python scripts for data transformation
Solution
Step 1: Understand what seeds are in dbt
Seeds are CSV files that contain static reference data you want to load into your database.
Step 2: Identify the main use of seeds
Seeds let you easily add fixed data tables without writing SQL queries.
Final Answer:
To load static reference data from CSV files into your database -> Option B
Quick Check:
Seeds = static CSV data load [OK]
Hint: Seeds = fixed CSV data loaded as tables [OK]
Common Mistakes:
Confusing seeds with models that run SQL
Thinking seeds schedule dbt runs
Assuming seeds are for dynamic data
2. Which command do you run to load or refresh seed data in your database?
easy
A. dbt test
B. dbt run
C. dbt seed
D. dbt compile
Solution
Step 1: Recall dbt commands related to seeds
The command dbt seed loads CSV seed files into the database as tables.
Step 2: Differentiate from other commands
dbt run runs models, dbt test runs tests, and dbt compile compiles SQL but does not load seeds.
Final Answer:
dbt seed -> Option C
Quick Check:
Load seeds = dbt seed [OK]
Hint: Use 'dbt seed' to load CSV data tables [OK]
Common Mistakes:
Using 'dbt run' to load seeds
Confusing 'dbt test' with loading data
Thinking 'dbt compile' loads data
3. Given a seed CSV file countries.csv with columns id and name, what will be the output of this dbt model SQL?
select * from {{ ref('countries') }}
medium
A. A table with all rows and columns from countries.csv
B. Only the id column from countries.csv
C. An empty table because seeds are not loaded automatically
D. An error because seeds cannot be referenced
Solution
Step 1: Understand how seeds are referenced in dbt
Seeds become tables in the database and can be referenced using ref() like models.
Step 2: Predict the query output
The query selects all columns and rows from the seed table countries, so it returns the full CSV data.
Final Answer:
A table with all rows and columns from countries.csv -> Option A
Quick Check:
ref(seed) = full seed table [OK]
Hint: ref(seed_name) returns full seed table [OK]
Common Mistakes:
Thinking seeds cannot be referenced
Assuming seeds load empty tables
Expecting partial columns only
4. You ran dbt seed but your seed table did not update. Which of these is the most likely cause?
medium
A. You forgot to add the seed CSV file in the seeds folder
B. You ran dbt run instead of dbt seed
C. Your seed CSV file has syntax errors
D. You did not configure the seed in dbt_project.yml
Solution
Step 1: Check seed discovery mechanism
dbt automatically discovers and loads CSV files from the seeds/ folder with dbt seed.
Step 2: Identify why table doesn't update
If the CSV file is missing from the seeds/ folder, dbt seed runs successfully but skips that seed, leaving the table unchanged.
Final Answer:
You forgot to add the seed CSV file in the seeds folder -> Option A
Quick Check:
Seeds folder missing CSV = no update [OK]
Hint: Place seed CSVs in seeds/ folder for dbt seed [OK]
Common Mistakes:
Thinking seeds require config in dbt_project.yml
Confusing dbt run with dbt seed
CSV syntax errors (would cause explicit failure)
5. You want to use a seed file currencies.csv with columns code and symbol inside a model to join with a transactions table on currency_code. Which is the correct way to write the join in your model SQL?
hard
A. select t.*, c.symbol from transactions t join currencies c on t.currency_code = c.code
B. select t.*, c.symbol from transactions t join currencies.csv c on t.currency_code = c.code
C. select t.*, c.symbol from transactions t join seed('currencies') c on t.currency_code = c.code
D. select t.*, c.symbol from transactions t join {{ ref('currencies') }} c on t.currency_code = c.code
Solution
Step 1: Recall how to reference seeds in dbt models
Seeds are referenced using {{ ref('seed_name') }} to get the table name in SQL.
Step 2: Identify the correct join syntax
Joining transactions with {{ ref('currencies') }} correctly uses the seed table in the join.
Final Answer:
select t.*, c.symbol from transactions t join {{ ref('currencies') }} c on t.currency_code = c.code -> Option D
Quick Check:
Join seed with ref() = correct [OK]
Hint: Use ref('seed_name') to join seed tables in models [OK]