SnowPro Associate: Platform exam dumps

SnowPro Associate: Platform practice question 90 of 367

SnowPro® Associate: Platform Certification. Associate level, Snowflake. Free question with the correct answer and a full explanation.

SnowPro Associate: Platform Question 90

Single answer● Python variable substitution

A data engineer is using Snowflake Connector for Python to run the same query for different warehouse names during an environment validation script. They want to avoid building SQL strings manually and instead use Snowflake SQL variable substitution supported by the Python connector. Which approach correctly enables variable substitution and references the variable in the SQL statement?

  1. A

    Execute SET wh_name='COMPUTE_WH' and then run SELECT * FROM INFORMATION_SCHEMA.WAREHOUSES WHERE WAREHOUSE_NAME = $wh_name in the same session.

  2. B

    Pass {'wh_name': 'COMPUTE_WH'} as a bind parameter dictionary and run SELECT * FROM INFORMATION_SCHEMA.WAREHOUSES WHERE WAREHOUSE_NAME = $wh_name without any session variable setup.

  3. C

    Run ALTER SESSION SET wh_name='COMPUTE_WH' and then query SELECT * FROM INFORMATION_SCHEMA.WAREHOUSES WHERE WAREHOUSE_NAME = :wh_name.

  4. D

    Set a Python variable wh_name = 'COMPUTE_WH' and run SELECT * FROM INFORMATION_SCHEMA.WAREHOUSES WHERE WAREHOUSE_NAME = wh_name because the connector substitutes Python variable names automatically.

Show answer and explanation

Correct answer: A

Explanation

The correct answer is to use Snowflake SQL session variables: define the variable with SET and reference it with a $ prefix in later SQL statements executed in the same session. This is the Snowflake-supported variable substitution pattern and is distinct from Python-side string formatting or connector bind parameters. For SnowPro Associate, it is important to distinguish among three concepts: Snowflake session variables (SET myvar='x' then use $myvar), session parameters (ALTER SESSION SET ...), and connector parameter binding. Best practice is to avoid manual string concatenation for dynamic values when a supported mechanism exists, because it improves correctness and reduces risk of malformed SQL. See Snowflake documentation on SQL variables/session variables and the Snowflake Connector for Python parameter binding behavior.

  • A. Correct.

    Correct. In Snowflake SQL, session variables are created with SET and referenced with a $ prefix, such as $wh_name. When using the Snowflake Connector for Python, statements executed on the same connection share the same session, so the script can first execute SET wh_name='COMPUTE_WH' and then use $wh_name in a subsequent SQL statement. This is the valid pattern for Snowflake SQL variable substitution.

  • B. Incorrect.

    Incorrect. This option mixes up Snowflake session variables with client-side bind variables. A Python dictionary of bind values is not the same as defining a Snowflake SQL session variable. If the SQL text uses $wh_name, Snowflake expects a session variable named wh_name to already exist. Bind parameters are handled differently and use parameter binding syntax supported by the connector, not $session_variable syntax.

  • C. Incorrect.

    Incorrect. ALTER SESSION SET is used for session parameters, not for creating arbitrary SQL variables. Also, :wh_name is not the Snowflake SQL syntax for referencing a session variable. Snowflake session variables are created with SET and referenced as $wh_name.

  • D. Incorrect.

    Incorrect. The Snowflake Connector for Python does not automatically inspect Python variable names inside SQL text and replace them. Writing WAREHOUSE_NAME = wh_name would be interpreted by Snowflake as an identifier or invalid expression context, not as the Python variable's value. Developers must use either proper session variables (SET plus $variable) or supported parameter binding.

Timed practice exam

Take a SnowPro Associate: Platform practice test under exam conditions

65 questions in 85 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam