Building stored procedures in SQL scripting, JavaScript, and Snowpark
Stored procedures in Snowflake execute procedural logic (control flow, loops, error handling) and can be written in JavaScript, SQL Scripting (Snowflake Scripting), Python, Java, or Scala. Unlike UDFs, stored procedures can perform DDL/DML side effects, run with caller's or owner's rights, and return a single value rather than being usable inline in a SELECT.
1 · Learn the must-know
- Stored procedures can execute DDL and DML statements and produce side effects, whereas UDFs cannot—this is the key distinguishing use case for choosing a procedure.
- EXECUTE AS CALLER runs the procedure with the invoking user's privileges, while EXECUTE AS OWNER (the default) runs with the privileges of the procedure's owner, which matters for security and privilege-escalation design.
- Snowflake Scripting (BEGIN...END blocks with DECLARE, variables, loops, IF/CASE, cursors, and RESULTSET) allows procedural SQL logic to be written natively without JavaScript.
- Python and Java stored procedures use the Snowpark API, requiring a specified
RUNTIME_VERSION, HANDLER, and PACKAGES/IMPORTS for external libraries staged in Snowflake. - Stored procedures can call other stored procedures and can return tabular results via CALL ... using RESULTSET or by returning a TABLE type, but they are invoked with CALL, not SELECT.
- Exception handling in Snowflake Scripting uses EXCEPTION blocks with system-defined or user-defined exceptions (via RAISE), enabling structured error handling within transformation pipelines.
2 · Check your understanding
A Snowflake Scripting stored procedure named APPLY_ADJUSTMENTS runs three sequential UPDATE statements in its body. The Engineer needs any SQL error raised by those statements to be caught, written as a row into the ERROR_LOG table containing the error code and message, and then re-thrown to the caller so the calling task still reports a Failed status.
Which procedure body meets all of these requirements?
What you have tried across SnowPro Advanced Data Engineer's objectives, not a readiness score.
Data Movement28% of the exam*0 of 7 tried
Performance Optimization19% of the exam*0 of 3 tried
Storage and Data Protection14% of the exam*0 of 3 tried
Data Governance14% of the exam*0 of 2 tried
Data Transformation25% of the exam*0 of 7 tried
* Our estimate. Snowflake publishes no section weights.
3 · Keep going
Ready for more? Take a weighted mock or try free practice questions.