【问题标题】:How to fetch the result using TDengine python connector如何使用 TDengine python 连接器获取结果
【发布时间】:2021-08-13 02:40:12
【问题描述】:

对于TDengine数据库的python连接器,我想得到查询结果而不是知道是否执行成功。我只想获取结果,我应该使用哪个 api?
我之前用过execute,但它只返回1表示成功,失败时返回其他错误。

【问题讨论】:

    标签: python tdengine


    【解决方案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() 
    

    希望这些对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-06
      • 2016-04-13
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 2011-04-10
      • 2014-11-08
      • 2020-08-23
      相关资源
      最近更新 更多