如果我在Vertica中复杂的SELECT之后提交(),为什么会出现pyodbc HY000错误?

时间:2014-02-03 18:06:11

标签: sql pyodbc vertica

我一直在追逐这个错误一周:

pyodbc.Error: ('HY000', '[HY000] [Vertica][VerticaDSII] (20) An error occurred during query execution:  (20) (SQLFetch)')

经过大量试验和错误后,关键是此特定SELECT查询(较简单的不发生错误)以及commit()之后对curs.execute()的调用的组合。我真的很想听听你的想法。下面(后面是配置信息)就是一个例子。任何帮助理解为什么会发生这种情况将非常感激。我很乐意提供更多细节,如果有帮助的话。

版本:

  • Python:3.3.2 [GCC 4.4.6 20120305(Red Hat 4.4.6-4)] on linux
  • pyodbc:3.0.7(pyodbc.SQL_DBMS_VER:18,pyodbc.SQL_DM_VER:171,pyodbc.SQL_DRIVER_ODBC_VER:77,pyodbc.SQL_DRIVER_VER:7,pyodbc.SQL_ODBC_VER:10)
  • unixODBC:2.2.14
  • vertica:Vertica Analytic Database v7.0.0-0
  • OS:Linux版本2.6.32-279.14.1.el6.x86_64(mockbuild@c6b8.bsys.dev.centos.org)(gcc版本4.4.6 20120305(Red Hat 4.4.6-4)(GCC) )

来源:

import pyodbc

query = '''
SELECT relVarTable0.id AS id, relVarTable1.val, relVarTable2.val, relVarTable3.val, relVarTable4.val
FROM (SELECT id FROM B) relVarTable0
LEFT JOIN
(SELECT B1.id AS id, AVG(A1.X) AS val
FROM B B1, AB AB1, A A1
WHERE B1.id = AB1.B_id AND A1.id = AB1.A_id AND A1.X IS NOT NULL
GROUP BY B1.id) relVarTable1
    ON relVarTable0.id = relVarTable1.id
LEFT JOIN
(SELECT B1.id AS id, B1.Y AS val
FROM B B1
WHERE B1.Y IS NOT NULL ) relVarTable2
    ON relVarTable0.id = relVarTable2.id
LEFT JOIN
(SELECT B1.id AS id, AVG(A1.W) AS val
FROM B B1, AB AB1, A A1
WHERE B1.id = AB1.B_id AND A1.id = AB1.A_id AND A1.W IS NOT NULL
GROUP BY B1.id) relVarTable3
    ON relVarTable0.id = relVarTable3.id
LEFT JOIN
(SELECT B1.id AS id, AVG(C1.Z) AS val
FROM B B1, BC BC1, C C1
WHERE B1.id = BC1.B_id AND C1.id = BC1.C_id AND C1.Z IS NOT NULL
GROUP BY B1.id) relVarTable4
    ON relVarTable0.id = relVarTable4.id;
'''

conn = pyodbc.connect('DSN=vertica_kdl_dsn;UserName=__;Password=__)
curs = conn.cursor()
curs.execute('SET search_path TO "$user", rcd_test, public, v_catalog, v_monitor, v_internal;')
curs.execute(query)
curs.commit()           # comment out to get no error
rows = curs.fetchall()  # if above commit called: pyodbc.Error: ('HY000', '[HY000] [Vertica][VerticaDSII] (20) An error occurred during query execution:  (20) (SQLFetch)')
curs.close()

1 个答案:

答案 0 :(得分:1)

仅供参考我在Vertica community forum获得了一个简单的解决方案:

  

在DSN [vertica_kdl_dsn]下的odbc.ini中添加ResultBufferSize = 0   节

(Hy000不是特别有用的错误信息!)