What is Seeds in dbt? | How do you use seeds in dbt?

Posted on by By admin, in DBT | 0

What is Seeds in dbt?

In dbt, seeds are SQL files containing raw data that can be loaded into your data warehouse as the initial dataset for further transformation. Seeds serve as a starting point for building dbt models and are typically used to load reference data or static datasets. When executed, dbt runs the SQL queries defined in seed files to populate tables in your data warehouse, allowing you to begin your analytics workflow with the required foundational data. Seeds are particularly useful for creating lookup tables, dimension tables, or any other data that doesn’t require transformation logic.

Here’s an example of a seed file:

Seed file (e.g., my_seed.sql):
-- my_seed.sql
-- Create a seed table named 'example_seed'
CREATE TABLE {{ ref('example_seed') }} (
    id INT,
    name VARCHAR(50),
created_at TIMESTAMP
);

-- Insert data into the 'example_seed' table
INSERT INTO {{ ref('example_seed') }} (id, name, created_at)
VALUES
    (1, 'John Doe', '2022-01-01'::TIMESTAMP),
    (2, 'Jane Smith', '2022-02-15'::TIMESTAMP);

In this example, the seed file defines a table named example_seed and inserts two rows of data into it. The {{ ref(‘example_seed’) }} syntax is a dbt Jinja variable that dynamically references the model or table in the data warehouse where the seed data will be loaded.

Usage in a model:

-- my_model.sql
-- Reference the seed table in your model
WITH seed_data AS (
    SELECT * FROM {{ ref('example_seed') }}
)

-- Perform additional transformations or analyses
SELECT
    id,
    name,
created_at
FROM
seed_data;

In the subsequent model (my_model.sql), the seed table example_seed is referenced, allowing you to build on top of this raw data by applying further transformations or analyses in your dbt workflow. This separation of raw data (seeds) and transformations (models) is a fundamental concept in dbt’s approach to analytics engineering.

We at Helical have more than 10 years of experience in providing solutions and services in the domain of data and have served more than 85+ clients. We are also DBT partners, hence in case if you are looking for certain assistance, consulting, services please do reach out on nikhilesh@Helicaltech.com

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments