How to Load Data Into Redshift With dbt
To load data into Redshift with dbt, write a SQL model that selects from your raw table, applies transforms, and run dbt run - dbt materializes it as a table automatically. The project wires the connection; you write the SQL.
How dbt loads data into Redshift
dbt (data build tool) is not an ingestion layer - it transforms data that is
already in the warehouse. You write a .sql file in models/, run dbt run,
and dbt executes your SELECT and materializes the result as a table (or view)
in the database. Redshift and Postgres share the same SQL dialect for everything
dbt touches, so dbt-postgres and dbt-redshift are interchangeable at the
model level.
The model file
A dbt model is just a SELECT. Put it in models/orders.sql:
SELECT
order_id,
customer_id,
total_cents / 100.0 AS total_dollars
FROM raw_orders
WHERE status = 'completed'
That is the complete model. dbt reads the file, wraps it in a CREATE TABLE AS
(because materialized = 'table' is set in dbt_project.yml), and runs it
against the warehouse.
Running the model
cd /workspace
dbt run
dbt prints each model name and whether it succeeded:
Running with dbt=1.x.x
Found 1 model, 0 tests
Concurrency: 1 threads
1 of 1 START table model public.orders ........................ [RUN]
1 of 1 OK created table model public.orders .................. [SELECT 3 in 0.12s]
Finished running 1 table model in 0.21s.
Completed successfully.
To inspect the result directly:
psql -h 127.0.0.1 -U postgres -d app -c "SELECT * FROM orders;"
Project wiring
Two config files connect the model to the warehouse:
dbt_project.yml- declares the project name, model paths, and default materialization (tablevsview).profiles.yml- holds the connection details (host, port, database, user, password). PointDBT_PROFILES_DIRat the directory containing this file:
DBT_PROFILES_DIR=/workspace dbt run
Staging, intermediate, and marts
In production dbt projects, you layer models:
- staging models (
stg_orders.sql) do light cleanup on raw tables - fix types, rename columns, cast nulls. - intermediate models join and enrich staging data.
- mart models (
orders.sql) are the final, BI-ready tables.
Models reference each other with ref() so dbt builds the full DAG and runs
them in dependency order:
-- models/orders.sql (mart referencing a staging model)
SELECT
order_id,
customer_id,
total_cents / 100.0 AS total_dollars
FROM {{ ref('stg_orders') }}
WHERE status = 'completed'
Add dbt test to catch not_null and unique violations on every run.
Want to try it hands-on? HeyDevJob gives you this exact setup in a live cloud workspace in your browser - edit it, run it, and see it work. Free, nothing to install.
Try it in a workspace →What you'll practice
- Writing a dbt SQL model that filters rows and transforms column values
- Running
dbt runand reading the materialization output - Connecting models with
ref()to build a staging-to-mart DAG
FAQ
How does dbt load data into Redshift?
dbt transforms data already in Redshift - you write a SELECT in a .sql model file, run dbt run, and dbt materializes the result as a table or view in the warehouse. It does not ingest raw data from outside the database.
What is the difference between dbt-postgres and dbt-redshift?
For standard SQL models - filters, joins, casts, aggregations - the SQL is identical. dbt-redshift adds Redshift-specific materializations like sort_key and dist_key. If your model is plain SQL, dbt-postgres works against a Redshift-compatible Postgres endpoint.
How do I reference one dbt model from another?
Use {{ ref('model_name') }} in your SELECT instead of the raw table name. dbt resolves the reference, builds a dependency graph (DAG), and runs models in the correct order.
Can you use dbt with Redshift?
Yes. dbt has a native Redshift adapter (dbt-redshift). You write SQL models and dbt run materializes them as tables or views in Redshift, just like any other warehouse.
Keep learning
Learn it by doing. Open this in a live cloud workspace, make the change yourself, and keep a record of the work you can share.
Open the workspace →