2

Connecting to SAP HANA using the official, semi-unsupported hdbcli Python module.

I'm trying to create a table from a subquery, which has some placeholders:

>>> 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: ')

(In my actual case I'm trying to create a temporary table, but this does not change the outcome)

If I change my query to a simple select from subquery instead of a CREATE TABLE, it works fine:

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

It also works if I change my inner SELECT to return a constant instead of using a placeholder:

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

UPDATE: I have tested this with the officially supported ODBC driver via pyodbc as well, and a very similar problem manifests:

>>> 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')

While a simple subselect still works via ODBC as well:

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

I am at a loss here; I've tried everything that I could think of, but still can't figure out why a CREATE TABLE query cannot use placeholders. Any help with figuring this mess out will be appreciated!

4

1 回答 1

1

我对 Hana Studio 进行了同样的尝试。它也失败了。所以这不是 Python 特有的。恕我直言,如果您在SAP 社区网络中提出这个问题,您将有更好的机会获得答案,因为这是专家所在的地方。

于 2014-02-10T08:42:48.323 回答