2017-05-13 73 views
0

我想在Hadoop上對Cloudera Impala中的python impyla查詢中的字符進行轉義,但似乎沒有任何工作..模板語法不能轉義(對於數據庫API ..)如何在python impyla中查詢運行在Hadoop上的Cloudera Impala中的字符

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庫?

+0

你能編輯這個來顯示產生的錯誤嗎? – Jared

回答

0

您可以使用參數化查詢與?佔位符

cursor.execute('INSERT INTO table VALUES (?, ?);', (var1, var2))

然而impyla確實仍然有報價轉義和Unicode,我還沒有完全想通了另一些問題。