Skip to main content

02. Working with Seeds

What Are Seeds in dbt?​

Seeds are CSV files that you include in your dbt project and load into your data warehouse as tables.
They are often used for:

  • Reference data (e.g., country codes, currency mappings)
  • Lookup tables
  • Static configurations

Why Use Seeds?​

  • Version-controlled static data
  • No need for external ETL for small reference tables
  • Easy to manage in Git and share with your team

How to Create a Seed?​

  1. Create a folder named data/ in your dbt project.
  2. Add a CSV file (e.g., currencies.csv):
currency_code,currency_name
USD,US Dollar
EUR,Euro
INR,Indian Rupee

How to Load Seeds into Your Warehouse?​

Run:

dbt seed

This creates a table in your warehouse:

analytics.data.currencies

Configuring Seeds in dbt_project.yml​

You can configure seeds globally:

seeds:
+schema: reference
+quote_columns: false

Or per seed file:

seeds:
my_project:
currencies:
+schema: lookup
+column_types:
currency_code: string

Applying Tests on Seeds​

Define tests in schema.yml:

version: 2

models:
- name: currencies
columns:
- name: currency_code
tests:
- not_null
- unique

Best Practices for Seeds​

Use seeds only for small, static datasets Store seeds in data/ folder under version control Keep column names lowercase and consistent Document and test seeds like other models


Seed Use Cases​

Seeds are ideal for supporting lookups, mappings, and small static datasets that are easier to maintain inside dbt than in separate ETL pipelines.

1️⃣ Country & Currency Reference​

  • Example: Mapping ISO country codes or currency codes to names.
country_code,country_name
US,United States
IN,India
UK,United Kingdom

2️⃣ Mapping Tables for Business Logic​

  • For categorizing data and applying consistent labels across models.
product_id,category
101,Electronics
102,Clothing
103,Books

3️⃣ Static Configuration Tables​

  • Example: thresholds, weights, or flags used in models.
metric,threshold
sales_target,50000
profit_margin,0.20

4️⃣ Hierarchy or Classification Data​

  • Store organization structures or product hierarchies.
dept_id,dept_name,parent_dept
10,Finance,NULL
20,Accounting,10
30,Payroll,10

5️⃣ Data Quality Rules​

  • Define validation rules as seeds for dynamic testing.
column_name,rule
customer_id,not_null
order_amount,positive

When NOT to Use Seeds​

Large datasets (use external tables instead) Frequently changing data (use staging tables or ETL pipelines)


Summary​

Seeds simplify managing static reference data within dbt. They are lightweight, version-controlled, and easily deployed.