Time Travel, Dynamic Tables & Stages
These three features come up in almost every Snowflake interview. Time Travel is about how you undo mistakes. Dynamic Tables are about how you build pipelines without orchestration code. Stages are about how data gets in at all.
Time Travel
Query, clone or restore data as it was at any point inside the retention period.How it works: micro-partitions are immutable. When you change data, the old micro-partitions are not deleted. They are kept for DATA_RETENTION_TIME_IN_DAYS. Time Travel is simply reading the set of micro-partitions that was current at an earlier moment, so it costs nothing extra in compute. You only pay for the storage of the old versions.
Retention rules
| Object | Standard edition | Enterprise+ | Fail-safe after |
|---|---|---|---|
| Permanent table / schema / database | 0 or 1 day (default 1) | 0–90 days (default 1) | 7 days |
| Transient table | 0 or 1 day | 0 or 1 day | None |
| Temporary table | 0 or 1 day (ends with session) | 0 or 1 day | None |
Retention can be set on the account, database, schema or table. The most specific setting wins. ACCOUNTADMIN can also set MIN_DATA_RETENTION_TIME_IN_DAYS at account level as a floor that nobody can go below.
-- Set retention ALTER TABLE orders SET DATA_RETENTION_TIME_IN_DAYS = 30; -- Query the past: by timestamp, by relative offset (seconds), or by statement SELECT * FROM orders AT (TIMESTAMP => '2026-10-15 09:00:00'::TIMESTAMP_LTZ); SELECT * FROM orders AT (OFFSET => -60*60); -- 1 hour ago SELECT * FROM orders BEFORE (STATEMENT => '01b2c3d4-0000-1234-0000-0001a2b3c4d5'); -- Compare now vs yesterday to find what changed SELECT * FROM orders AT (OFFSET => -86400) MINUS SELECT * FROM orders; -- Restore by cloning a point in time (instant, zero-copy) CREATE TABLE orders_fix CLONE orders AT (OFFSET => -3600); -- Bring back dropped objects UNDROP TABLE orders; SHOW TABLES HISTORY LIKE 'ORDERS'; -- dropped versions show a dropped_on value -- Row-level change feed over a window (requires change tracking) ALTER TABLE orders SET CHANGE_TRACKING = TRUE; SELECT * FROM orders CHANGES (INFORMATION => DEFAULT) AT (TIMESTAMP => DATEADD(hour, -2, CURRENT_TIMESTAMP()));
AT vs BEFORE: AT includes changes made by a statement at that exact point. BEFORE(STATEMENT => id) shows the data right before that statement ran. That makes it the precise tool for undoing one bad query.
-- adjust the controls
Time Travel: the hard questions
These edge cases separate people who have read the docs from people who have recovered production data.Dynamic Tables
Write theSELECT you want the table to equal. Snowflake keeps it within a freshness target.
A dynamic table is defined by a query and a target lag, the maximum acceptable staleness. Snowflake works out when to refresh, refreshes incrementally (processing only changed rows) when it can, and orders refreshes across a chain of dynamic tables. No streams, tasks, schedules or MERGE statements to write.
-- Bronze -> Silver: clean and deduplicate
CREATE OR REPLACE DYNAMIC TABLE silver.orders
TARGET_LAG = DOWNSTREAM -- refresh only when something downstream needs it
WAREHOUSE = transform_wh
REFRESH_MODE = AUTO -- INCREMENTAL if possible, otherwise FULL
AS
SELECT order_id, customer_id, amount, status, updated_at
FROM raw.orders
QUALIFY ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY updated_at DESC) = 1;
-- Silver -> Gold: business aggregate, must be at most 15 minutes stale
CREATE OR REPLACE DYNAMIC TABLE gold.daily_revenue
TARGET_LAG = '15 minutes'
WAREHOUSE = transform_wh
AS
SELECT DATE_TRUNC('day', o.updated_at) AS day, c.region, SUM(o.amount) AS revenue
FROM silver.orders o
JOIN silver.customers c USING (customer_id)
WHERE o.status = 'COMPLETE'
GROUP BY 1, 2;
-- Operate it
ALTER DYNAMIC TABLE gold.daily_revenue REFRESH; -- refresh now
ALTER DYNAMIC TABLE gold.daily_revenue SUSPEND; -- stop refreshing
ALTER DYNAMIC TABLE gold.daily_revenue SET TARGET_LAG = '1 hour';
SHOW DYNAMIC TABLES LIKE 'DAILY%'; -- see refresh_mode + reason
SELECT name, state, refresh_action, refresh_trigger,
refresh_start_time, refresh_end_time
FROM TABLE(information_schema.dynamic_table_refresh_history())
ORDER BY refresh_start_time DESC LIMIT 20;
| Dynamic table | Streams + Tasks | Materialized view | |
|---|---|---|---|
| Style | Declarative (one SELECT) | Imperative (you write MERGE / procedures) | Declarative |
| Joins, unions, window functions | Yes | Anything | Single table only |
| Freshness | Target lag (minimum 1 minute) | Your schedule or trigger | Always current at query time |
| Compute | Your warehouse | Your warehouse or serverless tasks | Serverless |
| Procedural logic, external calls, custom error handling | No | Yes | No |
| Best for | SQL transformation pipelines (bronze → silver → gold) | Complex CDC, SCD2 with custom rules, side effects | Speeding up one repeated aggregate |
Things that trip people up
- Target lag is a target, not a guarantee. Slow refreshes or an undersized warehouse lead to missed lag.
- Non-deterministic functions such as
CURRENT_TIMESTAMP()block incremental refresh. InAUTOmode the table silently becomesFULLrefresh, which can be expensive. - You can't
INSERT/UPDATEa dynamic table directly. Its content is defined by the query. - Incremental refresh needs change tracking on the base tables. Snowflake enables it if the owner has the privilege.
Cost levers
- Longer lag means fewer refreshes and fewer warehouse wake-ups.
- Use
DOWNSTREAMfor intermediate tables so they refresh only when the final table needs them. - Give dynamic tables their own warehouse with
AUTO_SUSPEND = 60. - Check
refresh_mode_reasoninSHOW DYNAMIC TABLESto confirm you gotINCREMENTAL.
Stage integrations and loads
The step-by-step AWS and Azure setup is in Module 03. This section covers the concepts and options you need in production.The four kinds of stage
| Stage | Reference | Created by | Use it for |
|---|---|---|---|
| User stage | @~ | Automatic, one per user | Personal files only you load |
| Table stage | @%orders | Automatic, one per table | Files that only ever load into that table. No file format object, no grants to others. |
| Named internal stage | @raw.landing | CREATE STAGE | Shared landing area inside Snowflake. Upload with PUT or the Snowsight UI. |
| Named external stage | @raw.s3_orders | CREATE STAGE … URL = … STORAGE_INTEGRATION = … | Files already in S3, Azure or GCS. This is the production default. |
Why storage integrations and not keys? A stage can be created with CREDENTIALS = (AWS_KEY_ID=… AWS_SECRET_KEY=…), but then secrets live in SQL text and query history and need manual rotation. An integration delegates trust to an IAM role or Azure service principal. STORAGE_ALLOWED_LOCATIONS limits which paths any stage built on it can reach. Many security teams require REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION = TRUE at account level.
COPY INTO options you'll actually use
| Option | What it does |
|---|---|
FILE_FORMAT | CSV, JSON, PARQUET, AVRO, ORC or XML, plus parsing options (delimiter, header skip, null handling). |
PATTERN / FILES | Regex or explicit list to pick a subset of files in the stage path. |
ON_ERROR | ABORT_STATEMENT (COPY default), CONTINUE, SKIP_FILE (Snowpipe default), SKIP_FILE_<n> or SKIP_FILE_<n>%. |
VALIDATION_MODE | RETURN_ERRORS or RETURN_<n>_ROWS: test without loading. |
MATCH_BY_COLUMN_NAME | Map Parquet/Avro/ORC/JSON (and CSV with header) fields to columns by name, not position. |
FORCE | Reload files even if load metadata says they were already loaded. Risk of duplicates. |
PURGE | Delete files from the stage after a successful load. Needs delete permission on external storage. |
SIZE_LIMIT | Stop picking new files after roughly this many bytes in one COPY. |
COPY INTO raw.orders (order_id, amount, order_ts, src_file, loaded_at)
FROM (
SELECT $1:order_id::NUMBER,
$1:amount::NUMBER(12,2),
$1:ts::TIMESTAMP_NTZ,
METADATA$FILENAME,
CURRENT_TIMESTAMP()
FROM @raw.s3_orders
)
FILE_FORMAT = (TYPE = JSON)
PATTERN = '.*2026/10/.*[.]json[.]gz'
ON_ERROR = 'SKIP_FILE';
-- Unload (export) works the other way round
COPY INTO @raw.s3_exports/daily_revenue/
FROM gold.daily_revenue
FILE_FORMAT = (TYPE = PARQUET)
HEADER = TRUE
OVERWRITE = TRUE;
COPY vs Snowpipe vs Snowpipe Streaming
| Bulk COPY | Snowpipe | Snowpipe Streaming | |
|---|---|---|---|
| Trigger | You run it (task, Airflow, dbt) | Cloud event notification or REST call per file | SDK / Kafka connector pushes rows |
| Compute | Your warehouse | Serverless | Serverless |
| Latency | Your schedule | Typically about a minute after the file lands | Seconds |
| Load history | Load metadata kept 64 days | Pipe metadata kept 14 days | Offset tokens per channel |
| Best for | Large nightly batches | Files trickling in all day | Event streams with no files at all |
Troubleshooting loads
-- What did COPY / Snowpipe do with each file in the last day?
SELECT file_name, status, row_count, row_parsed, first_error_message, last_load_time
FROM TABLE(information_schema.copy_history(
TABLE_NAME => 'RAW.ORDERS',
START_TIME => DATEADD(hour, -24, CURRENT_TIMESTAMP())))
ORDER BY last_load_time DESC;
-- Rows rejected by the last COPY job ('_last' = most recent in this session)
SELECT * FROM TABLE(VALIDATE(raw.orders, JOB_ID => '_last'));
-- Is the pipe running and receiving notifications?
SELECT SYSTEM$PIPE_STATUS('raw.orders_pipe');
-- Files that landed before the pipe existed (or while it was paused): backfill
ALTER PIPE raw.orders_pipe REFRESH; -- queues files staged in the last 7 days