Pyodbc 未检测 SQL 语句中的参数标记(即 - 插入 table SELECT ...)到 Hive table。这个问题有解决方法吗?

Pyodbc not detecting parameter marker in SQL statement (i.e. - Insert into table SELECT ...) to Hive table. Is there a workaround for this issue?

我的目标是遍历一组值并将它们用于 运行 一组查询,这些查询将把它们的结果插入到 hive table 使用 pyodbc。

我试过了

params = ['USA','JP']
set(params)

for i in params:
    cursor.execute(insert into table **some_db.some_tbl** SELECT name, country from **some_db.some_tbl_2** where country = ?,i)

并得到错误

the following and received the error message, ProgrammingError: ('The SQL contains 0 parameter markers, but 1 parameters were supplied', 'HY000').

如果我删除 insert into table some_db.some_tbl 部分,它工作正常。不确定还能做什么,因为所有文档和查看类似问题都表明我所做的是正确的。

如果我保留 insert into table some_db.some_tbl 部分但删除参数化,它工作正常。

我用一个简单的解决方法来回答这个问题,因为它可能会帮助其他人节省一些时间。

由于 'insert without parameterization''select with parameterization' 独立工作,我通过循环解决了这个问题我的参数带有 select 语句,然后将结果保存到 pandas 数据框。从那里,您可以 运行 针对 pandas 数据框插入,而无需为当前迭代设置参数。所有这些都将在循环体中,从而分别考虑所有参数值。