Guide
Snowflake Streams Guide: Types, Offsets, Tasks and Staleness
How Snowflake streams track changes to a table: standard, append-only and insert-only streams, the metadata columns, when the offset moves, merging changes with a task, and how to keep a stream from going stale.
A stream is Snowflake's built-in change data capture. Point one at a table and it tells you which rows were inserted, updated or deleted since you last read it, with a few metadata columns saying what happened to each. Paired with a task, it is the classic way to build an incremental pipeline inside Snowflake: land raw data, let the stream collect what changed, and have a task merge just those rows downstream. This guide covers the three kinds of stream, how the offset moves (the part most bugs come from), the SQL for a merge pipeline, and how to keep a stream from going stale.
What a stream is
A stream holds no data. It stores an offset: a point in the source table's version history. When you query it, Snowflake returns the rows that changed between that offset and now, in the same columns as the table plus three metadata columns. Think of it as a bookmark in the table's history; you can drop it, or place several at different points, without copying anything.
To do this, Snowflake needs change tracking on the table. Creating the first stream on a table switches it on, adding hidden columns that take a small amount of storage. If change tracking isn't on yet, only the table's owner (the role with OWNERSHIP) can create that first stream; after that, a role with SELECT on the table and CREATE STREAM on the schema can add more. The owner can also switch it on ahead of time:
ALTER TABLE raw.customers SET CHANGE_TRACKING = TRUE;
Streams can be created on standard tables (including shared tables), views (including secure views), dynamic tables, Iceberg tables, event tables, directory tables and external tables. They can't track materialized views. Snowflake's reference is Introduction to streams.
Stream types: standard, append-only and insert-only
| Type | What it returns | Use it for |
|---|---|---|
| Standard (the default) | The net delta: inserts, updates and deletes, including truncates. A row inserted and then deleted between two reads doesn't appear at all. | Keeping a downstream table in step with a source that changes in place. |
Append-only (APPEND_ONLY = TRUE) | Inserted rows only. Updates, deletes and truncates are ignored, so 10 rows inserted and 5 then deleted still come back as 10 inserts. | Insert-only landing tables and ELT, where it is notably cheaper to read than a standard stream. |
Insert-only (INSERT_ONLY = TRUE) | Rows from files added to cloud storage. Removed files are not recorded; an overwritten file comes back as new rows. | External tables and externally managed Iceberg tables, the only places it is supported. |
Which type a source supports depends on the object; the full matrix, including the Iceberg limits, is in Snowflake's documentation. Standard streams can't return change data for geospatial columns, so Snowflake recommends append-only streams for those tables. A stream's source and type can't be changed after it is created; drop it and create a new one.
Creating a stream
-- Standard stream on a table
CREATE STREAM raw.customers_stream ON TABLE raw.customers;
-- Append-only stream on an insert-only landing table
CREATE STREAM raw.events_stream ON TABLE raw.events APPEND_ONLY = TRUE;
-- Return the rows already in the table the first time it is read
CREATE STREAM raw.customers_backfill ON TABLE raw.customers
SHOW_INITIAL_ROWS = TRUE;
-- Start from a point in the past (within Time Travel)
CREATE STREAM raw.customers_replay ON TABLE raw.customers
AT(OFFSET => -60*60);
SHOW_INITIAL_ROWS = TRUE is the simple way to seed a new downstream table: the first read returns every row that existed when the stream was created, then the stream behaves normally. Creating a stream AT or BEFORE a past point only works back to when change tracking began on the table and within its Time Travel retention; before that, CREATE STREAM fails.
Reading a stream: the metadata columns
Every row a stream returns carries three extra columns:
METADATA$ACTION:INSERTorDELETE.METADATA$ISUPDATE:TRUEwhen the row is half of an update. AnUPDATEshows up as a pair: aDELETEwith the old values and anINSERTwith the new ones, both markedTRUE.METADATA$ROW_ID: a stable ID for the row, the same across every stream on that table.
Because a stream returns the net change between two points, a row inserted and then updated since the last read shows up as a single INSERT with the latest values and METADATA$ISUPDATE = FALSE. Your pipeline sees end states, not every intermediate step. If you need every step (a full audit trail), write the changes out on every run, or use the source system's own log.
SELECT id, email, METADATA$ACTION, METADATA$ISUPDATE
FROM raw.customers_stream;
-- id | email | METADATA$ACTION | METADATA$ISUPDATE
-- 7 | old@example.com | DELETE | TRUE -- update, old values
-- 7 | new@example.com | INSERT | TRUE -- update, new values
-- 9 | x@example.com | INSERT | FALSE -- new row
-- 4 | y@example.com | DELETE | FALSE -- deleted row
When the offset moves
This is the rule to get right. Querying a stream does not move its offset. A plain SELECT can be run as many times as you like and returns the same rows. The offset moves only when the stream is read inside a DML statement that commits: INSERT, MERGE, UPDATE, DELETE, CREATE TABLE ... AS SELECT or COPY INTO a location. When it commits, the stream advances to the start of that transaction, even if the statement wrote no rows.
Two consequences follow:
- Several statements, one set of changes. To write the same changes to two tables, wrap both statements in an explicit transaction. Streams use repeatable read: every statement inside the transaction sees the same rows, and the offset moves once, at
COMMIT. Run them as two autocommitted statements and the second one sees nothing.BEGIN; INSERT INTO core.customer_changes SELECT * FROM raw.customers_stream; MERGE INTO core.customers t USING raw.customers_stream s ON ...; COMMIT; - Skipping changes on purpose. To move a stream to now without processing what is in it, recreate it with
CREATE OR REPLACE STREAM, or consume it into a throwaway table with a filter that matches nothing:CREATE TEMPORARY TABLE _skip AS SELECT * FROM raw.customers_stream WHERE 1 = 0;
A transaction that rolls back leaves the offset where it was, so a failed run simply sees the same changes again next time.
Merging changes into a target table
The usual job for a standard stream is keeping a target table in step with its source. Drop the DELETE half of each update pair (the INSERT half has the new values), then merge on the key:
MERGE INTO core.customers t
USING (
SELECT *
FROM raw.customers_stream
WHERE NOT (METADATA$ACTION = 'DELETE' AND METADATA$ISUPDATE)
) s
ON t.id = s.id
WHEN MATCHED AND s.METADATA$ACTION = 'DELETE' THEN DELETE
WHEN MATCHED AND s.METADATA$ACTION = 'INSERT' THEN UPDATE
SET t.email = s.email, t.plan = s.plan, t.updated_at = s.updated_at
WHEN NOT MATCHED AND s.METADATA$ACTION = 'INSERT' THEN INSERT
(id, email, plan, updated_at) VALUES (s.id, s.email, s.plan, s.updated_at);
One case to plan for: if a key can be deleted and then inserted again as a new row between runs, the stream returns two rows for it (a DELETE and an INSERT, neither marked as an update), and MERGE fails on a key that matches twice. Keep one row per key first, preferring the insert:
SELECT * FROM raw.customers_stream
WHERE NOT (METADATA$ACTION = 'DELETE' AND METADATA$ISUPDATE)
QUALIFY ROW_NUMBER() OVER (
PARTITION BY id ORDER BY IFF(METADATA$ACTION = 'INSERT', 0, 1)
) = 1
For an append-only stream there are no updates or deletes to handle, so the step is an INSERT ... SELECT with whatever cleaning the landing data needs. If the source is a CDC feed from Postgres or MySQL, the source's own operation column usually decides inserts, updates and deletes instead; see our piece on change data capture into Snowflake.
Running it with a task
A task runs the merge for you. The WHEN SYSTEM$STREAM_HAS_DATA(...) condition makes it skip a run when there is nothing new, which avoids starting or resuming a warehouse for nothing.
-- On a schedule, but only when there are changes
CREATE TASK core.merge_customers
WAREHOUSE = transform_wh
SCHEDULE = '5 MINUTE'
WHEN SYSTEM$STREAM_HAS_DATA('raw.customers_stream')
AS
MERGE INTO core.customers t USING (...) s ON ...;
-- Triggered: runs when the stream has data, no schedule
CREATE TASK core.merge_customers_triggered
TARGET_COMPLETION_INTERVAL = '15 MINUTES' -- serverless: no WAREHOUSE
WHEN SYSTEM$STREAM_HAS_DATA('raw.customers_stream')
AS
MERGE INTO core.customers t USING (...) s ON ...;
-- Tasks are created suspended
ALTER TASK core.merge_customers RESUME;
A few things trip people up:
- Tasks start suspended. Nothing runs until
ALTER TASK ... RESUME. - False positives must still be consumed.
SYSTEM$STREAM_HAS_DATAnever misses changes but can returnTRUEwhen the stream turns out to be empty (for example, rows inserted and deleted again). The task body has to consume the stream in a DML statement every run, or the function keeps returningTRUEand the task keeps running. AMERGEorINSERT ... SELECTfrom the stream does this even when it writes nothing. - Streams on views fire more often. For a view, the check looks at the underlying tables, so a change the view filters out still counts.
- Triggered tasks have a floor. By default a triggered task runs at most every 30 seconds; the
USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDSparameter can lower it to 10. A serverless triggered task needsTARGET_COMPLETION_INTERVAL.
Our Snowflake tasks guide covers schedules, task graphs, privileges and failure handling in full. Snowflake documents the options in Introduction to tasks and Triggered tasks.
Staleness: how streams break
A stream reads the table's history, so it only works while its offset is inside the table's data retention period. Once the offset falls outside it, the stream is stale: its unconsumed changes are gone, and the only fix is to recreate the stream and backfill whatever it missed.
To make this less likely, when a table's retention is under 14 days and a stream on it hasn't been consumed, Snowflake temporarily extends the table's retention back to the stream's offset, up to MAX_DATA_EXTENSION_TIME_IN_DAYS (14 days by default) on every edition. Consuming the stream puts retention back to normal. So by default, a stream on a table with 1-day retention has to be consumed at least every 14 days.
SHOW STREAMS IN SCHEMA raw;
-- check the stale and stale_after columns
DESCRIBE STREAM raw.customers_stream;
stale_after is when the stream is expected to go stale (or went stale, if it's in the past). Treat it as a deadline: once it passes, the stream can go stale at any moment, even with nothing unconsumed. Calling SYSTEM$STREAM_HAS_DATA on an empty stream also keeps it from going stale, which is why a task with that WHEN clause, running on schedule, usually keeps its stream healthy.
Other things that make a stream stale or lose its changes:
CREATE OR REPLACE TABLEon the source drops its history and makes every stream on it stale. For a stream on a view, recreating or dropping any underlying table does the same. Pipelines that rebuild a table in full shouldTRUNCATEand reload, or swap, instead.- Dropping and recreating the source under the same name doesn't reconnect old streams to the new table. Renaming the source doesn't break anything.
- Cloning a schema or database copies the stream, but its unconsumed changes aren't reachable in the clone.
- Long pauses: an incident, a frozen deploy or a suspended task that outlasts the extension window. Raise retention on the source before a planned pause, not after; our Time Travel guide covers retention settings.
Streams on shared tables or views don't extend the provider's retention, so a consumer reading a share has to keep up within whatever retention the provider set.
One stream per consumer
Consuming a stream moves its offset for everyone. If two pipelines read the same stream, whichever commits first takes the changes and the other sees none. Give each consumer its own stream on the source: streams store only an offset, so extra ones cost very little.
CREATE STREAM raw.customers_to_core ON TABLE raw.customers;
CREATE STREAM raw.customers_to_search ON TABLE raw.customers;
Streams on views
A stream on a view returns changes to the view's result, which is handy for tracking a filtered or joined slice of several tables. The view's underlying tables need change tracking switched on, and the view can only use projections, filters, inner or cross joins and UNION ALL. GROUP BY, DISTINCT, QUALIFY, LIMIT and subqueries outside the FROM clause aren't supported, and functions in the select list must be built-in scalar functions. With a join, a change on either side is joined against the other table, so one new row on a small side can produce many stream rows.
The CHANGES clause: changes without a stream
If you only need to look at what changed between two points, without a pipeline consuming it, the CHANGES clause reads the same change tracking data without an offset:
SELECT *
FROM raw.customers
CHANGES(INFORMATION => DEFAULT)
AT(TIMESTAMP => DATEADD(hour, -6, CURRENT_TIMESTAMP()));
Use INFORMATION => APPEND_ONLY for inserts only, and an optional END(...) clause to close the window. It needs change tracking on the table (or a stream on it) from the start of the window, and it never consumes anything, so it is good for audits and debugging and a poor fit for pipelines, which need the offset to remember where they stopped.
Streams and tasks, or dynamic tables?
Dynamic tables now cover much of what streams and tasks were used for: you declare the query and a target lag, and Snowflake works out the incremental refresh and the schedule. For a chain of transformations, that is far fewer objects to run. Streams and tasks are still the better fit when you need explicit control over each change: slowly changing dimensions (type 2) that close out the old row and add a new one, side effects such as calling a procedure or exporting the changes, writing one set of changes to several tables in one transaction, or reacting to deletes in a specific way. Our piece on dynamic tables for incremental pipelines goes through that trade-off in detail.
What streams cost
A stream has no charge of its own. You pay for:
- Compute to read the stream, on the warehouse or serverless task that consumes it. Append-only streams are cheaper to read than standard ones because there are no deletes to join.
- Storage for the change tracking columns (small) and for any retention Snowflake extends while a stream sits unconsumed, billed like the rest of your storage.
Your credit and storage rates depend on your contract, edition, cloud and region; check them on your Snowflake order form or in Snowsight's cost management pages rather than relying on published list prices. Task runs are visible in TASK_HISTORY, and serverless task credits in SNOWFLAKE.ACCOUNT_USAGE.SERVERLESS_TASK_HISTORY.
Common questions
Does selecting from a stream consume it?
No. Only a DML statement that reads the stream and commits moves the offset. A SELECT, even inside an explicit transaction, leaves it where it was.
Why is my stream empty when the table changed?
Usually because another statement or task already consumed it, because the changes cancelled out (a row inserted and then deleted), or because it is an append-only stream and the changes were updates or deletes. Some writes, such as reclustering, don't produce change data at all.
Can a stream see changes made before it was created?
Only if you create it AT or BEFORE an earlier point, and only back to when change tracking was switched on for the table and within its retention. SHOW_INITIAL_ROWS = TRUE returns the current rows, not their history.
What happens to a stream when I add a column?
Streams use the table's current schema, so a new column appears in the stream. Changes that are incompatible with older rows still waiting in the stream (making a column NOT NULL, for example) can make queries on it fail until it is consumed.


