SOL-C01 practice question 2 of 30

How can Python variable substitution be performed in Snowflake notebooks?

Full set: 214 questions
Answer options
A: By manually editing data files
B: By configuring network settings
C: By using placeholders in SQL queries Correct answer
D: By writing HTML code
Correct Answer:
C. By using placeholders in SQL queries
Explanation

Snowflake Notebooks allow for seamless integration between Python and SQL cells. To use a Python variable within a SQL query, you can use a placeholder syntax. This is done by prefixing the Python variable name with a colon (e.g., SELECT FROM mytable WHERE id = :mypythonvariable;). Snowflake automatically substitutes the placeholder with the variable's value at runtime.

Why Incorrect

A: Manually editing data files is a data manipulation task and is not a method for programmatic variable substitution in code. B: Network settings are related to connectivity and security, not the logic of variable substitution within a notebook. D: HTML is a markup language for structuring web pages and has no role in passing variables to SQL queries.

References

1. Snowflake Documentation. (n.d.). Developing code in Snowflake Notebooks - Use Python variables in a SQL cell. Retrieved from https://docs.snowflake.com/en/user-guide/notebooks-develop#use-python-variables-in-a-sql-cell. (This section provides a direct example: "To use a Python variable in a SQL cell, use the variable name with a colon (:) as a prefix.").

Scroll to Top