0
0
dbtdata~5 mins

Loading CSV seeds in dbt

Choose your learning style9 modes available
Introduction

Loading CSV seeds lets you add small, fixed data files into your database easily. This helps you use simple data for testing or reference without writing complex code.

You want to add a list of countries or states to your project.
You need a small lookup table like product categories.
You want to test your models with fixed sample data.
You have static data that rarely changes but is needed in your analysis.
Syntax
dbt
1. Place your CSV file inside the 'seeds' folder in your dbt project.
2. Run the command: dbt seed
3. The CSV data will load into your database as a table with the same name as the CSV file.

The CSV file name becomes the table name in your database.

You can configure seed options like delimiter or header in the dbt_project.yml file.

Examples
This loads the 'countries.csv' file as a table named 'countries' in your database.
dbt
# Place 'countries.csv' inside the 'seeds' folder
# Run in terminal:
dbt seed
This configures the seed to expect a header row and comma delimiter.
dbt
# Example dbt_project.yml seed config
seeds:
  my_project:
    countries:
      header: true
      delimiter: ','
Sample Program

This example loads a small fruits list into your database. After running dbt seed, you can query the 'fruits' table to see the data.

dbt
# Step 1: Create a CSV file named 'fruits.csv' inside the 'seeds' folder with this content:
# name,color
# apple,red
# banana,yellow
# grape,purple

# Step 2: Run the seed command in terminal:
dbt seed

# Step 3: Query the loaded table in your dbt model or database:
select * from fruits;
OutputSuccess
Important Notes

Seeds are best for small, static datasets.

Running dbt seed overwrites the existing seed tables.

You can use seeds to simplify testing and prototyping.

Summary

Seeds load CSV files as tables in your database.

Place CSVs in the 'seeds' folder and run dbt seed.

Use seeds for small, fixed reference data.