从select结果创建表失败,错误292“参数数量错误:”

时间:2014-01-29 16:26:48

标签: python hana

使用官方的,半不受支持的hdbcli Python模块连接到SAP HANA。

我正在尝试从子查询创建一个表,该子查询包含一些占位符:

>>> cursor.execute('CREATE TABLE temporary_table AS (SELECT ? AS a FROM DUMMY) WITH DATA', [1])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/some-masked-path-here/hdbcli/dbapi.py", line 369, in execute
    ret = self.__execute(operation, tuple(parameters))
  File "/some-masked-path-here/hdbcli/dbapi.py", line 244, in __execute
    ret = self.__cursor.execute(operation, parameters=parameters, iscall=iscall)
Error: (292, 'wrong number of arguments: ')

(在我的实际情况中,我正在尝试创建一个临时表,但这不会改变结果)

如果我将查询更改为从子查询而不是CREATE TABLE进行简单选择,则可以正常工作:

>>> cursor.execute('SELECT * FROM (SELECT ? AS a FROM DUMMY) AS sub', [1])
True

如果我更改内部SELECT以返回常量而不是使用占位符,它也有效:

>>> cursor.execute('CREATE TABLE temporary_table AS (SELECT 1 AS a FROM DUMMY) WITH DATA', [])
True

更新:我也通过pyodbc通过官方支持的ODBC驱动程序对此进行了测试,并且出现了类似的问题:

>>> cursor.execute('CREATE TABLE temporary_table AS (SELECT ? AS a FROM DUMMY) WITH DATA', [1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.ProgrammingError: ('The SQL contains 0 parameter markers, but 1 parameters were supplied', 'HY000')

虽然简单的子选择仍然可以通过ODBC工作:

>>> cursor.execute('SELECT * FROM (SELECT ? AS a FROM DUMMY) AS sub', [1])
<pyodbc.Cursor object at 0xb70f0b80>

我在这里不知所措;我已经尝试了所有我能想到的,但仍然无法弄清楚为什么CREATE TABLE查询不能使用占位符。任何帮助解决这个烂摊子的人都将不胜感激!

1 个答案:

答案 0 :(得分:1)

我和Hana Studio一样尝试过。它也失败了。所以这不是Python特有的。恕我直言,如果您在SAP community network中提出答案,那么您有更好的机会获得答案,因为这是专家所在的地方。