r/DataBuildTool•
Crow2525

Flatten DBT models into a single compiled query

Question

Background:

I build dbt models in a sandbox environment, but our data services team needs to run the logic as a single notebook or SQL query outside of dbt.

Request:

Is there a way to compile a selected pipeline of dbt models into one stand-alone SQL query, starting from the source and ending at the final table?

Solutions I've Tried:

  • I tried converting all models to ephemeral, but this fails when macros like dbt_utils.star or dbt_utils.union_relations are used, since they require dbt's compilation context.

  • I also tried copying compiled SQL from the target folder, but with complex pipelines, this quickly becomes confusing and hard to manage. I'm looking for a more systematic or automated approach.

Posted Aug 24, 2025, 10:45 PM UTC

12
Loading comments…