【发布时间】:2019-09-14 18:23:59
【问题描述】:
我想从 MSSQL 表中读取然后插入到 MySQL 表中,但我无法将我的 MSSQL 结果格式化为executemany
cursor.execute('select * from table') # MSSQL
rows = cursor.fetchall()
many_rows = []
for row in rows:
many_rows.append((row))
sql = "insert into mysql.table VALUES (NULL, %s) on duplicate key update REFCOLUMN=REFCOLUMN" # MYSQL
mycursor.executemany(sql, many_rows)
mydb.commit()
这给了Failed executing the operation; Could not process parameters
第一个 NULL 用于 id 列, %s 用于其他 49 列。它以 1 比 1 的方式工作,但远程连接需要很长时间
编辑
many_rows 的示例打印输出:
[
(49 columns' values, all string and separated by comma),
(49 columns' values, all string and separated by comma),
(49 columns' values, all string and separated by comma),
...
]
【问题讨论】:
-
“第一个 NULL 用于 id 列,%s 用于其他 49 列” 但是您只为 1 个 [non-ID] 列提供了占位符...。多少行我们在谈论吗?你能提供一个实际的minimal reproducible example吗?
-
真实的minimal reproducible example 请不要模拟
-
@LightnessRacesinOrbit 这实际上是我的代码,除了超长的表名
-
所以构造一个我们可以实际诊断的minimal reproducible example。到目前为止,您还没有提供任何真实的问题演示。