03. Example: is_incremental() Behavior
This page explains when is_incremental() returns True and when it returns False.
is_incremental() activation rules
is_incremental() is activated (returns True) only when all of these conditions are met:
- Model is configured as incremental
{{ config(materialized='incremental') }}
- The target table already exists in the database
- You are running without
--full-refresh
Example 1: First Run
Suppose the table doesn't exist yet.
dbt run --select customer_orders
dbt creates the table for the first time.
Result:
is_incremental() = False
The incremental block is skipped:
{% if is_incremental() %}
AND o.ORDER_DATE > (
SELECT MAX(ORDER_DATE)
FROM {{ this }}
)
{% endif %}
Example 2: Second Run
The table already exists.
dbt run --select customer_orders
Result:
is_incremental() = True
Now the incremental filter is added to the SQL.
Example 3: Full Refresh
Even if the table exists:
dbt run --full-refresh
Result:
is_incremental() = False
Because dbt is rebuilding everything from scratch.
Example 4: Materialized as Table
{{ config(materialized='table') }}
Run:
dbt run
Result:
is_incremental() = False
because the model is not incremental.
Easy way to remember
| Scenario | is_incremental() |
|---|---|
| First run (table doesn't exist) | False |
| Incremental model + table exists | True |
dbt run --full-refresh | False |
Materialized as table | False |
Materialized as view | False |