Pyodbc: ('params Must Be In A List, Tuple, Or Row', 'hy000') With Numpy Data
Solution 1:
As stated in the comments to the question, the issue was that
cursor.executemany(sql, params)
was failing because
params = list(row for row in data_table.round(0).head(10).to_records(index=False))
was not returning a list of "list[s], tuple[s], or [pyodbc] Row[s]", it was returning a list of "numpy.records". The solution was to convert the "records" so that params
contained a list of tuples:
params = list(tuple(row) for row in data_table.head(10).values)
Solution 2:
I think it is important to point out that if you use tuple(__item__)
, your strings will be seperated by every char ... think of your string as a C++ const char pointer. The tuple is taking that item of const chars pointers and putting all the elemetns into a tuple. To stop this you can put your string in a list as so: tuple([__string__])
. The list will not stay in the tuple it is just saying put this WHOLE item of const char pointers as one element into my tuple. Hope this was helpful, recently had this problem at work.
Post a Comment for "Pyodbc: ('params Must Be In A List, Tuple, Or Row', 'hy000') With Numpy Data"