我提到How to use variables in SQL statement in Python?
但无法得到答案。
我正在尝试你的建议,但我得到了这个错误 - :(
tbl_nm = 'EMPLOYEE_TABLE'
con.execute('select max(emp_id) from schema.?', tbl_nm)
获得以下错误:
Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/site-packages/impala/hiveserver2.py", line 302,
in execute configuration=configuration) File "/usr/local/lib/python2.7/site-packages/impala/hiveserver2.py", line 343,
in execute_async self._execute_async(op) File "/usr/local/lib/python2.7/site-packages/impala/hiveserver2.py", line 362,
in _execute_async operation_fn() File "/usr/local/lib/python2.7/site-packages/impala/hiveserver2.py", line 334,
in op parameters) File "/usr/local/lib/python2.7/site-packages/impala/interface.py", line 267,
in _bind_parameters
raise ProgrammingError("Query parameters argument should be a "
impala.error.ProgrammingError: Query parameters argument should be a list, tuple, or dict object
>
答案 0 :(得分:1)
建议您将查询作为字符串存储到变量中,并将其传递给execute方法,而不是将原始配置单元查询直接传递给execute方法。
在你的情况下:
tbl_nm = 'EMPLOYEE_TABLE'
query = "select max(emp_id) from schema.{}".format(tbl_nm)
con.execute(query)
如果有帮助,请告诉我。