Run the consumer through a triggered task
Connect a task to the stream signal and let its body call the same transaction-owning procedure already exercised manually.
Understand the idea
Reuse the procedure rather than maintaining separate manual and scheduled MERGE logic. The task owner role must have procedure USAGE plus all caller-rights source, stream, scratch and target permissions. Fully qualified names make the context explicit.
| Concept | What it means |
|---|---|
| WHEN | Checks the stream’s change signal. |
| CALL | Runs the complete processing procedure. |
| RESUME | Allows automatic execution. |
| SUSPEND | Stops future scheduling; does not guarantee an in-flight run has stopped. |
A concrete example
After history shows SUCCEEDED, active 103 should be version 2 amount 75. The active total is 125 including order 102.
Remember: Choose one active execution path for a shared consumer.
Explain it step by step · full theory
Understand the concept
Reuse the procedure rather than maintaining separate manual and scheduled MERGE logic. The task owner role must have procedure USAGE plus all caller-rights source, stream, scratch and target permissions. Fully qualified names make the context explicit.
Start with one manually submitted run while the task remains suspended. Observe TASK_HISTORY to completion before inspecting results. Do not also run the task graph introduced later against the same stream.
Walk through the behavior
Automatic execution is optional. Resume only after understanding permissions and billing, then append a new test event and inspect history. Suspend afterward. A trigger signals potential changes, so the procedure must also handle an empty interval correctly.
Words used in this lesson
- WHEN
- Checks the stream’s change signal.
- CALL
- Runs the complete processing procedure.
- RESUME
- Allows automatic execution.
- SUSPEND
- Stops future scheduling; does not guarantee an in-flight run has stopped.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Run the consumer through a triggered task
Start with the source
Connect a task to the stream signal and let its body call the same transaction-owning procedure already exercised manually.
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
- Start with the source
Connect a task to the stream signal and let its body call the same transaction-owning procedure already exercised manually.
- Follow the work
Reuse the procedure rather than maintaining separate manual and scheduled MERGE logic. The task owner role must have procedure USAGE plus all caller-rights source, stream, scratch and target permissions. Fully qualified names make the context explicit.
- Explain the outcome
Choose one active execution path for a shared consumer.
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 learning lab; nothing runs on this website. Complete lesson 1 setup in L2_OBJECTS_LAB.M11_LAB and follow the lesson order. Use the same authorized role and warehouse for manual SQL. Task templates use <lab_warehouse>: replace it with an approved warehouse name. Do not activate several consumers against the same stream. Each task starts suspended; running or resuming it can consume compute credits.
Create and manually exercise the real task
CREATE TASK PROCESS_EVENTS WAREHOUSE=<lab_warehouse>
USER_TASK_TIMEOUT_MS=60000 SUSPEND_TASK_AFTER_NUM_FAILURES=3
WHEN SYSTEM$STREAM_HAS_DATA('L2_OBJECTS_LAB.M11_LAB.EVENT_CHANGES')
AS CALL L2_OBJECTS_LAB.M11_LAB.APPLY_EVENTS(FALSE);
INSERT INTO ORDER_EVENTS VALUES (6,103,2,'UPSERT',75);
EXECUTE TASK PROCESS_EVENTS;What to expect and why
After history shows SUCCEEDED, active 103 should be version 2 amount 75. The active total is 125 including order 102.
Inspect, optionally resume, then suspend
SELECT NAME,STATE,ERROR_MESSAGE,QUERY_ID,SCHEDULED_TIME,COMPLETED_TIME
FROM TABLE(L2_OBJECTS_LAB.INFORMATION_SCHEMA.TASK_HISTORY(TASK_NAME=>'PROCESS_EVENTS',RESULT_LIMIT=>20))
ORDER BY SCHEDULED_TIME DESC;
-- Optional automatic operation, not required for the manual lab:
-- ALTER TASK PROCESS_EVENTS RESUME;
-- After observing the intended run:
ALTER TASK PROCESS_EVENTS SUSPEND;What to expect and why
Inspect terminal states before continuing. SUSPEND prevents future scheduling but does not replace checking an ongoing execution.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Which identity needs the underlying table privileges?
Compare your reasoning
The task owner role used for execution, because the called procedure uses caller rights.