Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What is {{ this }}?

dbt · Incremental Models & Performance

What is {{ this }}?

Mediumdbt-28
thisjinjaincrementalhooks

Question

What does {{ this }} mean in dbt?

Solution

{{ 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:

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

Hooks or custom logic that need the destination table name:

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

Mental model

While building fct_orders:
  {{ this }}  →  analytics.fct_orders   (resolved for the target)
  {{ ref('stg_orders') }} → upstream 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."

PreviousNext