【发布时间】:2021-08-13 02:40:12
【问题描述】:
对于TDengine数据库的python连接器,我想得到查询结果而不是知道是否执行成功。我只想获取结果,我应该使用哪个 api?
我之前用过execute,但它只返回1表示成功,失败时返回其他错误。
【问题讨论】:
对于TDengine数据库的python连接器,我想得到查询结果而不是知道是否执行成功。我只想获取结果,我应该使用哪个 api?
我之前用过execute,但它只返回1表示成功,失败时返回其他错误。
【问题讨论】:
tdengine的githup 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()
希望这些对你有帮助。
【讨论】: