如何使用 TDengine python 连接器获取结果
How to fetch the result using TDengine python connector
对于TDengine数据库的python连接器,我想获取查询结果,而不是知道是否执行成功。我只想获取结果,我应该使用哪个 api?
我以前用过 execute
但它只有 returns 1
表示成功,失败时会出现其他错误。
tdengine github repos中有一些例子,链接是https://github.com/taosdata/TDengine/tree/develop/tests/examples/python
# query data and return data in the form of list
try:
c1.execute('select * from db.t')
except Exception as err:
conn.close()
raise(err)
# Column names are in c1.description list
cols = c1.description
# Use fetchall to fetch data in a list
data = c1.fetchall()
for col in data:
print(col)
print('Another query method ')
try:
c1.execute('select * from db.t')
except Exception as err:
conn.close()
raise(err)
# Use iterator to go through the retreived data
for col in c1:
print(col)
conn.close()
希望这些可以帮到你
对于TDengine数据库的python连接器,我想获取查询结果,而不是知道是否执行成功。我只想获取结果,我应该使用哪个 api?
我以前用过 execute
但它只有 returns 1
表示成功,失败时会出现其他错误。
tdengine github repos中有一些例子,链接是https://github.com/taosdata/TDengine/tree/develop/tests/examples/python
# query data and return data in the form of list
try:
c1.execute('select * from db.t')
except Exception as err:
conn.close()
raise(err)
# Column names are in c1.description list
cols = c1.description
# Use fetchall to fetch data in a list
data = c1.fetchall()
for col in data:
print(col)
print('Another query method ')
try:
c1.execute('select * from db.t')
except Exception as err:
conn.close()
raise(err)
# Use iterator to go through the retreived data
for col in c1:
print(col)
conn.close()
希望这些可以帮到你