To execute a Snowflake query with the help of binds, follow these steps:
Define the parameters that you want to bind in your query. For example, let's say you want to bind the value of a column called "user_id".
Use the "?" placeholder in your query where you would normally enter the value of the parameter. For example, your query might look like this:
SELECT * FROM users WHERE user_id = ?
conn = snowflake.connector.connect( user="UserName", password="xxxxxx", account="xxxxxxx", )
curs = conn.cursor()
query = "SELECT * FROM users WHERE user_id = ?"
curs.execute(query, (1234,))
This will execute the query with the value of 1234 bound to the "user_id" parameter.
result = curs.fetchall()
This will return a list of dictionary objects where each dictionary represents a row in the result set.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-04-16 11:00:00 +0000
Seen: 8 times
Last updated: Aug 22 '21