我试图在 Hadoop 上对 Cloudera Impala 的 python impyla 查询中的字符进行转义,但似乎没有任何效果。模板语法没有转义(对于数据库 API 来说不寻常。)
cursor.execute('SELECT * from table where col1 = %s', tuple(["John's unescaped string"]))
产生错误。
甚至
cursor.execute('SELECT * from table where col1 = %s', tuple([json.dumps("John's unescaped string")]))
不起作用,有没有人知道如何为此提供解决方案?有没有更好的方法或更全功能的 Python 的 Impala 库?
最佳答案
您可以使用带有 ?
的参数化查询。占位符cursor.execute('INSERT INTO table VALUES (?, ?);', (var1, var2))
然而 impyla 仍然存在我尚未完全弄清楚的引号转义和 unicode 的其他问题。
关于python - 如何在 Hadoop 上运行的 Cloudera Impala 的 python impyla 查询中转义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43954104/