How to Use dbt utils
Last updated July 25, 2026 · By the SaturnSQL team
dbt-utils is the standard macro package: add it to packages.yml and run dbt deps to install. Popular macros include generate_surrogate_key for hashed keys, date_spine for calendar tables, and extra generic tests like expression_is_true.
packages.yml sits next to dbt_project.yml. Pinning to a version range rather than one exact version lets you pick up patch releases without breaking on a major one. Packages install into dbt_packages/, which belongs in .gitignore since it is fully reproducible from this file.
# packages.yml
packages:
- package: dbt-labs/dbt_utils
version: [">=1.0.0", "<2.0.0"]dbt deps downloads the package and has to be re-run whenever packages.yml changes, plus on any fresh checkout or CI runner. dbt refuses to compile with a clear error when packages are missing, so this is a required step rather than an optional one.
dbt depsSurrogate key and date spine
generate_surrogate_key hashes the listed columns into one deterministic key and handles NULLs consistently, so two rows differing only in a NULL do not collide. date_spine generates one row per interval and is the usual base for a calendar dimension, normally wrapped in its own model. Both are namespaced with the dbt_utils. prefix.
SELECT
{{ dbt_utils.generate_surrogate_key(['customer_id', 'order_date']) }} AS order_key
FROM {{ ref('stg_orders') }}
-- calendar table
{{ dbt_utils.date_spine(
datepart='day',
start_date="cast('2024-01-01' as date)",
end_date="cast('2027-01-01' as date)"
) }}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