dbt · Incremental Models & Performance

What is {{ this }}?

Mediumthisjinjaincrementalhooks

Interview question

What does {{ this }} mean in dbt?

How to answer

The short answer

{{ this }} is a Jinja context variable that points at the relation currently being built: the model's own database.schema.table (or equivalent).

Common uses

Incremental watermarks:

SQL
{% if is_incremental() %}
where updated_at > (select max(updated_at) from {{ this }})
{% endif %}

Hooks or custom logic that need the destination table name:

SQL
{{ config(
    post_hook="grant select on {{ this }} to role reporter"
) }}

Mental model

Difference from ref('same_model')

You generally should not ref yourself. {{ this }} is the self-pointer for the relation under construction. On first run before the table exists, queries against {{ this }} inside is_incremental() blocks are skipped because is_incremental() is false.

Interview tip: "{{ this }} is the model writing to itself; ref is how you read other models."