SnowPro Associate: Platform Question 70
Single answer● Run codeA data engineering team wants to let analysts run custom Python logic directly in Snowflake to score customer records without moving data to an external system. The analysts need to execute the code on demand as part of SQL workflows, and the solution must return tabular results that can be queried in Snowflake. Which Snowflake feature is the best fit for this requirement?
- A
Create a Python stored procedure and call it from SQL
- B
Create a Python UDF that returns a table of rows
- C
Create a Python worksheet in Snowsight and use it as a reusable SQL object
- D
Create a Snowflake Scripting block because it can run Python logic inline with SQL
Show answer and explanation
Correct answer: A
Explanation
The best answer is to use a Python stored procedure. For SnowPro Associate-level knowledge, candidates should understand which Snowflake features are intended for running code in different contexts. Stored procedures support procedural business logic and can be called from SQL workflows, making them a practical choice when teams need to execute Python on demand inside Snowflake. Python worksheets are primarily for authoring and testing code in Snowsight, while Snowflake Scripting is SQL-based procedural logic rather than Python execution. Snowflake documentation distinguishes among UDFs, stored procedures, worksheets, and Snowflake Scripting by execution model and return behavior. Best practice is to package reusable operational logic as stored procedures when the code must be invoked repeatedly from SQL-based workflows.
- A. Correct.
Correct. A Python stored procedure is designed to run Python code inside Snowflake and can be invoked from SQL using CALL. Stored procedures are well suited for operational workflows, orchestration, and returning results for downstream processing. In Snowflake, stored procedures can encapsulate Python logic and execute on demand as part of SQL-driven processes.
- B. Incorrect.
Incorrect. In Snowflake, Python UDFs return scalar values, not tabular result sets. Returning a table of rows is associated with table functions, but Python UDFs themselves are not the mechanism for returning tabular results in the way described here. This option reflects a common misconception that all code extensions can return any result shape interchangeably.
- C. Incorrect.
Incorrect. A Python worksheet in Snowsight is a development interface for writing and testing Python code, not a reusable database object that SQL workflows can directly invoke like a stored procedure. Worksheets are useful for interactive development, but they are not the right deployment mechanism for production SQL workflows.
- D. Incorrect.
Incorrect. Snowflake Scripting supports procedural SQL logic, such as variables, loops, and exception handling, but it does not execute Python inline. This option is plausible because Snowflake Scripting is used for control flow, but it is not the feature used to run Python code.