0
0
dbtdata~10 mins

Seeds for static reference data in dbt - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Seeds for static reference data
Create CSV file with static data
Place CSV in 'data' folder
Define seed in dbt project
Run 'dbt seed' command
dbt loads CSV into database as table
Use seed table in models/queries
This flow shows how you create a CSV file with static data, place it in your dbt project, run dbt seed to load it into your database, and then use it in your data models.
Execution Sample
dbt
id,name,category
1,Apple,Fruit
2,Carrot,Vegetable
3,Banana,Fruit
This CSV file contains static reference data for items with their categories.
Execution Table
StepActionInput/CommandResult
1Create CSV fileid,name,category 1,Apple,Fruit 2,Carrot,Vegetable 3,Banana,FruitCSV file saved in 'data/items.csv'
2Place CSV in data folderMove 'items.csv' to 'data/''data/items.csv' available in project
3Run dbt seeddbt seedCSV loaded into database as table 'items'
4Use seed table in modelSELECT * FROM {{ ref('items') }}Query returns static reference data from seed table
5Modify CSV and rerun seedUpdate CSV and run dbt seedDatabase table 'items' updated with new data
6ExitNo more actionsStatic data ready for use in dbt models
💡 Static CSV data loaded into database as a seed table and ready for use.
Variable Tracker
VariableStartAfter Step 1After Step 3After Step 5Final
CSV fileNoneCreated with 3 rowsLoaded into database as table 'items'Updated with new dataFinal seed table in database
Database table 'items'NoneNoneCreated with CSV dataUpdated with new CSV dataReady for queries
Key Moments - 3 Insights
Why do we need to place the CSV file in the 'data' folder?
dbt looks for seed files only in the 'data' folder, so placing the CSV there allows 'dbt seed' to find and load it, as shown in execution_table step 2.
What happens when we run 'dbt seed'?
The command reads all CSV files in the 'data' folder and loads them into the database as tables, replacing existing seed tables, as seen in execution_table step 3.
Can we update the seed data after initial load?
Yes, by modifying the CSV file and rerunning 'dbt seed', the database table updates with new data, shown in execution_table step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result after running 'dbt seed' the first time?
ACSV file is created
BCSV file moved to 'data' folder
CCSV loaded into database as table 'items'
DQuery returns static reference data
💡 Hint
Check execution_table row 3 under 'Result'
At which step does the static data become available for queries in dbt models?
AStep 3
BStep 4
CStep 2
DStep 5
💡 Hint
Look at execution_table where the seed table is referenced in a query
If you update the CSV file but forget to run 'dbt seed' again, what happens?
ASeed table remains unchanged in database
BDatabase table updates automatically
Cdbt throws an error
DCSV file is deleted
💡 Hint
Refer to execution_table step 5 about updating CSV and rerunning seed
Concept Snapshot
Seeds in dbt are CSV files with static data.
Place CSVs in the 'data' folder.
Run 'dbt seed' to load CSVs as tables.
Use seed tables in models with {{ ref() }}.
Update CSV and rerun seed to refresh data.
Full Transcript
Seeds for static reference data in dbt involve creating CSV files with fixed data, placing them in the 'data' folder of your dbt project, and running the 'dbt seed' command. This command loads the CSV data into your database as tables. You can then use these seed tables in your dbt models by referencing them with the ref function. If you update the CSV files, rerunning 'dbt seed' updates the database tables accordingly. This process helps manage static data easily within your dbt workflows.