Seeds let you add small, fixed tables to your project easily. They help keep important reference data ready to use without extra setup.
Seeds for static reference data in dbt
Start learning this pattern below
Jump into concepts and practice - no test required
1. Create a CSV file with your static data inside the 'seeds' folder. 2. Run 'dbt seed' to load the CSV as a table in your database. 3. Use the seeded table in your models like any other table.
The CSV file name becomes the table name in your database.
You can configure seed options like delimiter or header in your dbt_project.yml file.
# File: seeds/countries.csv
country_code,country_name
US,United States
CA,Canada
MX,Mexicodbt seed
select * from {{ ref('countries') }}
This example shows how to add a small static table of colors using seeds. The CSV file is loaded as a table, then used in a model.
# Step 1: Create a CSV file named 'colors.csv' inside the 'seeds' folder with this content: # color_id,color_name # 1,Red # 2,Green # 3,Blue # Step 2: Run the seed command in your terminal: dbt seed # Step 3: Create a model file 'models/color_names.sql' with this SQL: select * from {{ ref('colors') }} # Step 4: Run the model: dbt run # Step 5: Query the model output to see the seeded data: select * from color_names;
Seeds are best for small, static datasets. Large or frequently changing data should use other methods.
Remember to run 'dbt seed' whenever you update your CSV files to refresh the tables.
You can customize seed behavior in dbt_project.yml, like setting file encoding or quoting.
Seeds let you add fixed reference data as tables using CSV files.
They are easy to update and use inside your dbt models.
Run 'dbt seed' to load or refresh the data in your database.
Practice
seeds in dbt?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 BQuick Check:
Seeds = static CSV data load [OK]
- Confusing seeds with models that run SQL
- Thinking seeds schedule dbt runs
- Assuming seeds are for dynamic data
Solution
Step 1: Recall dbt commands related to seeds
The commanddbt seedloads CSV seed files into the database as tables.Step 2: Differentiate from other commands
dbt runruns models,dbt testruns tests, anddbt compilecompiles SQL but does not load seeds.Final Answer:
dbt seed -> Option CQuick Check:
Load seeds = dbt seed [OK]
- Using 'dbt run' to load seeds
- Confusing 'dbt test' with loading data
- Thinking 'dbt compile' loads data
countries.csv with columns id and name, what will be the output of this dbt model SQL?select * from {{ ref('countries') }}Solution
Step 1: Understand how seeds are referenced in dbt
Seeds become tables in the database and can be referenced usingref()like models.Step 2: Predict the query output
The query selects all columns and rows from the seed tablecountries, so it returns the full CSV data.Final Answer:
A table with all rows and columns from countries.csv -> Option AQuick Check:
ref(seed) = full seed table [OK]
- Thinking seeds cannot be referenced
- Assuming seeds load empty tables
- Expecting partial columns only
dbt seed but your seed table did not update. Which of these is the most likely cause?Solution
Step 1: Check seed discovery mechanism
dbt automatically discovers and loads CSV files from theseeds/folder withdbt seed.Step 2: Identify why table doesn't update
If the CSV file is missing from theseeds/folder,dbt seedruns successfully but skips that seed, leaving the table unchanged.Final Answer:
You forgot to add the seed CSV file in the seeds folder -> Option AQuick Check:
Seeds folder missing CSV = no update [OK]
- Thinking seeds require config in dbt_project.yml
- Confusing dbt run with dbt seed
- CSV syntax errors (would cause explicit failure)
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?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
Joiningtransactionswith{{ 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 DQuick Check:
Join seed with ref() = correct [OK]
- Using raw CSV filename in SQL
- Forgetting to use ref() for seeds
- Trying to use a non-existent seed() function
