我试图使用游标来玩这个简单的SQL查询:
import jaydebeapi,pandas as pd
conn = <connection to TeraData>
cursor = conn.cursor()
sql = ("Select top 10 * from Car_Sales")
data = cursor.execute(sql)
print(data.query)
row = data.fetchone()
#rows = data.fetchall()
print(row)
我得到的错误是:
AttributeError:'NoneType'对象没有属性'fetchone'
已经有几个小时试图找到问题,但没有得到任何结果。在线查看不同的资源,但问题仍然存在。
请让我知道我哪里错了?
更新:
当我在Pandas中执行相同的查询时:
pd.read_sql_query('select top 10 * from Car_Sales',conn)
输出:
Car_Sales
0 112
1 77
2 226
3 990
4 552
5 887
你没有告诉我们你正在使用哪个连接库,但是在我熟悉的情况下(psycopg
等),cursor.execute()
不会返回结果集。尝试针对fetchone
(而不是fetchall
)发布cursor
和data
命令:
conn = <connection to TeraData>
cursor = conn.cursor()
cursor.execute("Select top 10 * from Car_Sales")
row = cursor.fetchone()
print(row)
# rows = cursor.fetchall()
# print(rows)
更新
来自Blckknght的评论的一个小窍 - 看看Python Database API Spec:cursor.execute
的“返回值没有定义”。