0
0
Snowflakecloud~20 mins

Stored procedures in Python in Snowflake - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Snowflake Python Stored Procedure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding Python Stored Procedure Output in Snowflake
What will be the output of this Snowflake Python stored procedure when called?
CREATE OR REPLACE PROCEDURE test_proc()
RETURNS STRING
LANGUAGE PYTHON
AS
$$
  def run():
    return 'Hello from Snowflake!'
$$;
AThe procedure raises a syntax error due to missing RETURN keyword
BThe procedure returns the string 'Hello from Snowflake!'
CThe procedure returns NULL because no explicit RETURN statement is used
DThe procedure returns an empty string
Attempts:
2 left
💡 Hint
Remember that the function inside the procedure must return a value explicitly.
Configuration
intermediate
2:00remaining
Correct Syntax for Defining a Python Stored Procedure in Snowflake
Which of the following is the correct way to define a Python stored procedure in Snowflake that returns an integer 42?
A
CREATE OR REPLACE PROCEDURE get_answer()
RETURNS INTEGER
LANGUAGE PYTHON
AS
$$
  def run():
    return 42
$$;
B
CREATE PROCEDURE get_answer()
RETURNS INTEGER
LANGUAGE PYTHON
AS
$$
  return 42
$$;
C
CREATE OR REPLACE PROCEDURE get_answer()
RETURNS INTEGER
LANGUAGE PYTHON
AS
$$
  def run():
    return '42'
$$;
D
CREATE OR REPLACE PROCEDURE get_answer()
RETURNS INTEGER
LANGUAGE PYTHON
AS
$$
  def run():
    print(42)
$$;
Attempts:
2 left
💡 Hint
The procedure must define a run() function that returns the correct type.
Architecture
advanced
2:00remaining
Best Practice for Handling Exceptions in Snowflake Python Stored Procedures
You want to ensure your Python stored procedure in Snowflake handles errors gracefully and returns a meaningful message instead of failing silently or crashing. Which approach is best?
AUse print statements inside run() to log errors but do not catch exceptions
BLet exceptions propagate naturally so Snowflake logs the error automatically
CWrap the run() function code in try-except blocks and return error messages as strings
DReturn NULL on any error without catching exceptions
Attempts:
2 left
💡 Hint
Think about how to provide clear feedback from your procedure to callers.
security
advanced
2:00remaining
Security Consideration When Using Python Stored Procedures in Snowflake
Which of the following is a key security best practice when creating Python stored procedures in Snowflake?
AAlways run procedures with ACCOUNTADMIN role for full access
BDisable all access controls to simplify procedure execution
CStore sensitive credentials directly inside the procedure code for quick access
DLimit the procedure's privileges by assigning minimal roles and avoid using ACCOUNTADMIN
Attempts:
2 left
💡 Hint
Think about the principle of least privilege.
🧠 Conceptual
expert
2:00remaining
Behavior of Variable Scope in Snowflake Python Stored Procedures
Consider this Python stored procedure in Snowflake:
CREATE OR REPLACE PROCEDURE scope_test()
RETURNS STRING
LANGUAGE PYTHON
AS
$$
  x = 'outer'
  def run():
    x = 'inner'
    return x
$$;

What is the value returned when calling scope_test()?
A'inner' because the run() function returns its local x variable
B'outer' because the outer x variable is returned by default
CNULL because x is not returned explicitly
DSyntaxError due to variable shadowing
Attempts:
2 left
💡 Hint
Remember how Python handles variable scope inside functions.