Reputation: 371
I am trying to play around with this simple sql query using cursor:
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)
Error I am getting is:
AttributeError: 'NoneType' object has no attribute 'fetchone'
It has been couple hours trying to find the issue but not getting anywhere on this. Looked different resources online but still the issue remains.
Please let me know where am I going wrong?
Update:
When I executed the same query in Pandas:
pd.read_sql_query('select top 10 * from Car_Sales',conn)
Output:
Car_Sales
0 112
1 77
2 226
3 990
4 552
5 887
Upvotes: 0
Views: 9096
Reputation: 2073
You haven't told us which connection library you're using, but in cases I'm familiar with (psycopg
, etc) cursor.execute()
doesn't return a result set. Try issuing the fetchone
and fetchall
commands against the cursor
(rather than 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)
Update
A tidbit from Blckknght's comment - take a look at the Python Database API Spec: "Return values are not defined" for cursor.execute
.
Upvotes: 5