How to Use the ref Function in dbt

Last updated July 25, 2026 · By the SaturnSQL team

{{ ref('model_name') }} references another dbt model and compiles to its fully qualified table name. Always use ref instead of hardcoding names: it makes dbt build models in the right order, powers the DAG and lineage, and follows the target schema across dev and prod.

SELECT
  o.order_id,
  c.customer_name
FROM {{ ref('stg_orders') }} o
JOIN {{ ref('stg_customers') }} c
  ON c.customer_id = o.customer_id

Why never hardcode

A hardcoded analytics.stg_orders breaks when you run in a dev schema and is invisible to dbt's dependency graph, so the model may run before its parent exists. ref resolves to the right database and schema for the current target and registers the edge in the DAG.

Run this in SaturnSQL

SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.

Try it free

Related dbt guides

© 2026 Panda Capital Oy Ab. All rights reserved.