2

我提到了如何在 Python 的 SQL 语句中使用变量?

但无法得到答案。

我正在尝试您的建议,但我收到此错误 - :(

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

>
4

1 回答 1

1

建议您将查询作为字符串存储到变量中并将其传递给执行方法,而不是将原始配置单元查询直接传递给执行方法。

在你的情况下:

tbl_nm = 'EMPLOYEE_TABLE'
query = "select max(emp_id) from schema.{}".format(tbl_nm)
con.execute(query)

让我知道这是否有帮助。

于 2018-05-24T12:42:33.757 回答