我尝试在for循环中插入数据但是在将一些数据提交到数据库之后崩溃我假设它因为我尝试INSERT到许多数据。所以我想要一些建议来处理这个问题
for value in list:
cursor.execute("INSERT INTO table_name (filed1, filed2, filed3, filed4, filed5) VALUES (%d, %d, %d, %d, %d)", (var1, var2, var3, var4, var5))
conn.commit()
conn.close()
>
cursor.execute("INSERT INTO ScanEMAxEMAHistoryDay (SecurityNumber, EMA1, EMA2, CrossType, DayCross) VALUES (%d, %d, %d, %d, %d)", (id, item[0][0], item[0][1], value[0], value[1]))
File "pymssql.pyx", line 449, in pymssql.Cursor.execute (pymssql.c:7184)
File "_mssql.pyx", line 1011, in _mssql.MSSQLConnection.execute_query (_mssql.c:11594)
File "_mssql.pyx", line 1042, in _mssql.MSSQLConnection.execute_query (_mssql.c:11474)
File "_mssql.pyx", line 1159, in _mssql.MSSQLConnection.format_and_run_query (_mssql.c:12615)
File "_mssql.pyx", line 1181, in _mssql.MSSQLConnection.format_sql_command (_mssql.c:12876)
File "_mssql.pyx", line 1815, in _mssql._substitute_params (_mssql.c:20639)
File "_mssql.pyx", line 1798, in _mssql._quote_data (_mssql.c:20347)
File "_mssql.pyx", line 1768, in _mssql._quote_or_flatten (_mssql.c:19919)
ValueError: expected a simple type, a tuple or a list
答案 0 :(得分:0)
我遇到了同样的问题。我的输入数据类型是float32。我将它更改为float64后,它的工作原理。你可以尝试一下。