Andrzej Drzystek
02/13/2024, 9:18 AMAttributeError: 'SnowflakeCursor' object has no attribute 'execute_query'
I see this was already raised in #ask-ai channel but no working answer was provided. Would appreciate any guidelines. Thanks!Matt Clarke
02/13/2024, 9:28 AMsqlalchemy
, and snowflake-connector-python
. If I recall correctly, one of them uses conn.execute_query()
, whilst the other uses conn.cursor().execute_query()
Matt Clarke
02/13/2024, 9:44 AMsnowflake-io-manager
no longer uses the sqlalchemy
backend, and as a result some .cursor()
calls had to be added to the middle of the call chain, so something has changed in this domain recently.Andrzej Drzystek
02/13/2024, 9:45 AMMatt Clarke
02/13/2024, 10:29 AMcontext.resources.snowflake.execute_query(QUERY, fetch_results=True)
Matt Clarke
02/13/2024, 10:29 AMMatt Clarke
02/13/2024, 10:29 AMexecute_query
method you need to drop the .cursor()
from your command.Matt Clarke
02/13/2024, 10:30 AMexecute
rather than execute_query
Matt Clarke
02/13/2024, 10:34 AMwith self.get_connection() as conn:
with conn.cursor() as cursor:
cursor.execute(sql_query, parameters)
return cursor.fetchall()
In the backend, the execute query method is doing something along these linesMatt Clarke
02/13/2024, 10:34 AMMatt Clarke
02/13/2024, 10:35 AMMatt Clarke
02/13/2024, 10:35 AMfetch_arrow
or fetch_pandas_batches
Matt Clarke
02/13/2024, 10:36 AMAndrzej Drzystek
02/13/2024, 10:43 AM.cursor()
, i.e., using having just
with snowflake.get_connection() as conn:
return conn.execute_query(QUERY)
doesn’t help, getting then
AttributeError: 'SnowflakeConnection' object has no attribute 'execute_query'
I also tried execute
method, i.e.,
with snowflake.get_connection() as conn:
conn.cursor().execute(QUERY)
but then I’m getting
TypeError: cannot pickle '_thread.lock' object
Andrzej Drzystek
02/13/2024, 10:58 AM.fetch_pandas_all()
to the previous call, i.e.,
with snowflake.get_connection() as conn:
return conn.cursor().execute(QUERY).fetch_pandas_all()
then it works!