Python Connector for Snowflake

Querying data - Python Connector for Snowflake

Querying data

Once connected, you can execute SQL queries to retrieve data from your Snowflake database.

Execute a query

  1. Create a cursor object using the cursor() connection method.
    my_cursor = my_connection.cursor()
  2. Execute a SQL query using the execute() cursor method.
    my_cursor.execute("SELECT * FROM employees")
  3. Retrieve results using one of the fetch*() methods.
    for row in my_cursor.fetchall(): 
        print(row)

Parameterized queries

You can use parameterized queries to pass variable values to your SQL statements. This allows you to reuse the same query with different data and helps to prevent SQL injection attacks.

Pass parameters as a list or tuple to the execute() method:

for row in my_cursor.fetchall(): 
    print(row)

Each placeholder ? in the query is replaced with a corresponding value from the parameter list.

© 2022-2025 Devart. All Rights Reserved. Request Support Python Connectors Forum Provide Feedback