Final lab: choose declarative or procedural processing
Use dynamic tables for maintained query results. Keep streams and tasks where you need explicit transactions, conditional orchestration or side effects.
Understand the idea
Module 11 processes versioned immutable events using a procedure, tombstones and explicit stream consumption. This lab starts with a current-state order table and maintains query results. Comparing their totals without first aligning source semantics would be misleading.
| Concept | What it means |
|---|---|
| Dynamic-table path | Define the result and freshness objective. |
| Stream/task path | Define consumption, transaction and execution logic. |
| Hybrid path | Dynamic result → stream → task or procedure. |
| Migration | Compare equivalent inputs and outputs before cutover. |
A concrete example
Module 11 processes versioned immutable events using a procedure, tombstones and explicit stream consumption. This lab starts with a current-state order table and maintains query results. Comparing their totals without first aligning source semantics would be misleading.
Remember: Keep procedural effects explicit; choose a declarative, procedural or hybrid pipeline from the actual contract.
Explain it step by step · full theory
Understand the concept
Module 11 processes versioned immutable events using a procedure, tombstones and explicit stream consumption. This lab starts with a current-state order table and maintains query results. Comparing their totals without first aligning source semantics would be misleading.
A business operation that calls an external API, sends a notification or coordinates multiple writes does not become a pure SELECT by moving it into a dynamic-table definition. Use an explicit task/procedure boundary and design retries and idempotence for those actions.
Apply it to our pipeline
For migration, identify keys, duplicate handling, deletion semantics, permissions and freshness requirements. Build the new result beside the old path, reconcile it on the same input snapshot, then switch consumers with a rollback plan. Avoid two independent writers updating one shared target during cutover.
The final SQL compares direct source aggregation with the stored customer totals after the ordered lab. Because the previous lesson suspended refreshes, do not mutate RAW_ORDERS before this comparison. The complete lab should end with A=130, B=40 and an empty consumed stream.
Before calling a real deployment ready, inspect refresh history, owner privileges, monitoring and the recovery procedure for downstream streams. This website supplies a manual exercise; it does not claim these operations ran in your Snowflake account.
Words used in this lesson
- Dynamic-table path
- Define the result and freshness objective.
- Stream/task path
- Define consumption, transaction and execution logic.
- Hybrid path
- Dynamic result → stream → task or procedure.
- Migration
- Compare equivalent inputs and outputs before cutover.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Final lab: choose declarative or procedural processing
Read the dependency
Use dynamic tables for maintained query results. Keep streams and tasks where you need explicit transactions, conditional orchestration or side effects.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Read the dependency
Use dynamic tables for maintained query results. Keep streams and tasks where you need explicit transactions, conditional orchestration or side effects.
- Observe the result
Both summaries show A/1/130 and B/1/40. Difference query returns no rows and pending is 0. If not, compare source state and the last successful refresh before changing the definition.
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Manual Snowflake practice only. This website does not run SQL or provision compute. Refreshing dynamic tables uses billable resources.
Final lab: choose declarative or procedural processing — manual SQL
Definition: Use dynamic tables for maintained query results. Keep streams and tasks where you need explicit transactions, conditional orchestration or side effects.
When to use: Practise in the isolated M12_LAB schema.
Example: Both summaries show A/1/130 and B/1/40. Difference query returns no rows and pending is 0. If not, compare source state and the last successful refresh before changing the definition.
SELECT CUSTOMER_ID,COUNT(*) AS ORDER_COUNT,SUM(AMOUNT) AS TOTAL_AMOUNT
FROM RAW_ORDERS WHERE STATUS='PAID' GROUP BY CUSTOMER_ID ORDER BY CUSTOMER_ID;
SELECT * FROM CUSTOMER_TOTALS ORDER BY CUSTOMER_ID;
WITH expected AS (
SELECT CUSTOMER_ID,COUNT(*) AS ORDER_COUNT,SUM(AMOUNT) AS TOTAL_AMOUNT
FROM RAW_ORDERS WHERE STATUS='PAID' GROUP BY CUSTOMER_ID
), missing AS (SELECT * FROM expected MINUS SELECT * FROM CUSTOMER_TOTALS),
extra AS (SELECT * FROM CUSTOMER_TOTALS MINUS SELECT * FROM expected)
SELECT 'MISSING_OR_DIFFERENT' AS ISSUE,* FROM missing
UNION ALL SELECT 'EXTRA_OR_DIFFERENT',* FROM extra;
SELECT COUNT(*) AS PENDING FROM CLEAN_CHANGES;What to expect and why
Both summaries show A/1/130 and B/1/40. Difference query returns no rows and pending is 0. If not, compare source state and the last successful refresh before changing the definition.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Explain why: Can every task with external side effects be replaced by a dynamic-table SELECT?
Compare your reasoning
Keep procedural effects explicit; choose a declarative, procedural or hybrid pipeline from the actual contract.