Reputation: 789
I am trying to execute a select * query on snowflake using snowflake connector for python and while trying to add response data to a list getting following error : 'SnowflakeCursor' object has no attribute 'to_dict'
This is my source code
conn = snowflake.connector.connect(
user=****,
password=****,
account=****,
warehouse=****,
host=****
)
cmd = conn.cursor()
for i in self.queries:
cmd.execute(i['query'])
data_sets.append(list(cmd.to_dict()))
return data_sets
Getting the exception while doing cmd.to_dict(). Can anyone help me fix this?
Upvotes: 0
Views: 4545
Reputation: 5215
Calling to_dict
on cmd
(which is a cursor object) doesn't seem to make a lot of sense -- you'd probably want to use the cmd.fetchall()
to return the query's results as a list, and then cast the list elements to dictionaries.
There is probably an easier approach, however, and it's in using the DictCursor
variant of cursor
(which represents rows as dicts, rather than as tuples).
Here's how your modified code would look:
from snowflake.connector import DictCursor
cmd = conn.cursor(DictCursor)
for i in self.queries:
cmd.execute(i['query'])
data_sets.append(cmd.fetchall())
Upvotes: 6