DatabaseError:sql:SELECT上的执行失败

时间:2015-02-18 15:47:02

标签: sql select pandas teradata pyodbc

我使用以下代码连接到Teradata,我在python控制台上执行:

conn = pyodbc.connect('DRIVER={Teradata}; DBCNAME=TdwB; UID=####;PWD=###;')
query = file(full_path).read()
opportunities = pd.read_sql(query, conn)
conn.close()

query中,我从文件中读取了一个非常简单的SQL查询,一切正常。

然后,我尝试运行一个更复杂的查询,预计返回约350000行(0.2 GB)。我确信该查询有效,因为它已在SQL Assistant,Teradata查询工具上完美执行。

在5分钟之后,脚本以DatabaseError: Execution failed on sql: SELECT失败(我希望查询运行大约10-20分钟)。

我不知道如何解决这个问题,因为错误信息相当神秘。

  • 是暂停吗?
  • 数据格式问题?

匿名查询

最初超过300行,但它只是一个选择。以下是数据的主要操作:

SELECT 

TRUNC (CAST (a.created_at AS DATE ), 'M') AS first_day_month
,d.country_name AS country
,d.contract_id AS contract_id 
,MAX (TRIM(CAST(REGEXP_REPLACE(contracts.BillingStreet, '\||\n|\r|\t', '_',1,0,'m') AS CHARACTER(2048))) || ', ' || TRIM(contracts.BillingPostalCode) || ', ' || TRIM(contracts.BillingCity)) AS FullAdress
,MIN (CAST (bills.created_at AS DATE )) AS first_transaction
,SUM (gross_revenue ) 

FROM db_1.billings AS bills
LEFT JOIN  db_2.contracts AS contracts ON bills.deal_id = contracts.deal_id 

WHERE bills.economic_area = 'NA'
AND CAST (bills.created_at AS DATE ) >= TRUNC (ADD_MONTHS (CURRENT_DATE -1, - 26) , 'MM')
AND bills.country_id = 110

GROUP BY 1,2,3

有趣的是:

conn = pyodbc.connect('DRIVER={Teradata}; DBCNAME=####; UID=####;PWD=####;', timeout=0)
cursor = conn.cursor()
query = file(full_path).read()
cursor.execute(query)
row = cursor.fetchone()
if row:
    print row
cursor.close()
conn.close()

结果

Traceback (most recent call last):
  File "C:\Users\mferrini\AppData\Local\Continuum\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2883, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-19-8f156c658077>", line 6, in <module>
    cursor.execute(query)
Error: ('HY000', '[HY000] [Teradata][ODBC Teradata Driver][Teradata Database] Wrong Format  (-9134) (SQLExecDirectW)')

0 个答案:

没有答案