Use immutability constraints¶
To tell Snowflake that certain rows won’t change in a dynamic table,
use the IMMUTABLE WHERE clause in a CREATE DYNAMIC TABLE or
ALTER DYNAMIC TABLE statement.
Immutability makes refreshes faster by skipping rows that don’t change. Backfill with immutability provides both immediate and ongoing performance benefits:
Initial creation: Backfill copies historical data instantly without computation costs. This makes tables with years of historical data immediately available instead of requiring expensive initial refreshes.
Ongoing refreshes: Immutability constraints protect backfilled data from reprocessing during future refreshes. Only the mutable region gets refreshed, keeping refresh times fast even as the table grows.
For conceptual background, see Understanding immutability constraints.
Basic examples¶
Example: Prevent recomputation when a dimension table changes¶
When you update a row in a dimension table, reprocess only the facts from the mutable period:
Example: Retain data longer than the source table¶
Create a dynamic table that retains parsed data longer than the staging table, and delete old staging data with a task:
Example: Let downstream tables use incremental refresh from a full refresh table¶
Some query constructs (like Python user-defined table functions) require full refresh mode. Immutability constraints let downstream tables still use incremental refresh:
Backfill examples¶
The following examples show how to create new dynamic tables from tables with backfilled data.
The backfill table must contain matching columns with compatible data types in the same order as your dynamic table. Snowflake doesn’t copy table properties or privileges from the backfill table.
If you specify the Time Travel parameters AT | BEFORE, Snowflake copies data from the backfill table at the specified time.
The following limitations apply when you work with immutability constraints and backfilled data:
Currently, only regular and dynamic tables can be used for backfilling.
You can’t specify policies or tags in the new dynamic table because they are copied from the backfill table.
Clustering keys in the new dynamic table and backfill table must be the same.
Example: Backfill from a part of the table¶
The following example backfills the immutable region of my_dynamic_table from my_backfill_table and the mutable region from the dynamic
table’s definition.
When you reinitialize this dynamic table:
Incremental refresh mode: Snowflake deletes all mutable rows and repopulates only the mutable region.
Full refresh mode: Snowflake performs a full refresh with the same effect.
Example: Use backfill to recover or modify data in a dynamic table¶
You can’t directly edit a dynamic table’s data or definition. To recover or fix data, complete the following workaround steps:
Clone the dynamic table to a regular table.
Modify the cloned table as needed.
Backfill from the edited table into a new dynamic table.
In the following example, my_dynamic_table aggregates daily sales data from the sales base table:
Optionally, you can archive the old data to save storage cost:
Later, you find a sales error on 2025-05-01, where sales_count should be 2. To correct this:
Clone
my_dynamic_tableto a regular table:Update the cloned table:
Recreate the dynamic table by using the edited clone as the backfill source.
This method lets you recover or correct data in a dynamic table without modifying the base table:
Example: Modify a dynamic table’s schema by using backfill¶
You can’t directly alter the schema of a dynamic table. To update the schema — for example, add a column — follow these steps:
Clone the dynamic table to a regular table. The following example uses
my_dynamic_tablecreated fromsales(earlier).Modify the schema of the cloned table:
Optionally, add data to the new column.
Recreate the dynamic table by using the edited clone as the backfill source.
Verify that the new column appears in the dynamic table:
Check immutability status¶
To check whether a row is mutable in a dynamic table, query the METADATA$IS_IMMUTABLE column:
To view the immutability constraint on a dynamic table, run SHOW DYNAMIC TABLES and check the
immutable_where column.