dbt Compile Queries

dbt Compile Queries #

Everytime dbt runs, it compiles the SQL and stores the results in the ./target/compiled directory.

So if say there’s a model that includes aliases, the compiled form replaces those aliases with the actual values required to execute SQL.

For instance, a Jinja-templated model might look like:

with prep as (
    from {{source('something', 'other')}}
),

final as (
    select * from prep
)

select * from final

(where something refers to a database, other refers to a table defined in a .yml file in the ./model directory)

Might become something like the following ./target/compiled/.../<filename>.sql:

with prep as (
    from <database>.<schema>.<table>
),

final as (
    select * from prep
)

select * from final

^ Super handy for debugging.

Resources #