【问题标题】:Using InfluxDB difference function in Python在 Python 中使用 InfluxDB 差分函数
【发布时间】:2020-04-16 07:03:52
【问题描述】:

再扩展一下Using InfluxDB difference function,我有

select difference("e") from Energy where time >= now() - 24h

select difference("e") from Energy where time >=
'2020-04-14T00:00:01Z' and time <= '2020-04-15T20:00:01Z'

两者都在时间搜索仅涵盖 2 个用于减法的数据点的情况下工作。

但是如何在 python 脚本中实现这一点?我拥有的最好的是

response = client.query(select difference("e") from Energy where time
>= now() - 24h)

但它返回一个无效的语法错误。 在 python 中实现 difference() 的任何线索?

【问题讨论】:

    标签: python influxdb


    【解决方案1】:

    您的整个查询必须是一个 python 字符串。尝试类似:

    response = client.query('select difference("e") from Energy where time >= now() - 24h')
    

    【讨论】:

    • 谢谢。是的,这在 bash 中有效:influx -database EnergTotal -execute 'select difference("e") from Energy where time &gt;= now() - 24h' 但是为 python 获取正确的语法是一个挑战,因为它需要数据库名称。我在response = client.query('database=EnergTotal select difference("e") from Energy where time &gt;= now() - 24h') 周围尝试了多种选择,但均未成功。
    【解决方案2】:

    查询必须是第一个,然后是数据库名称:

    response = client.query('select difference("e") from Energy where time >= now() - 24h', database='EnergTotal')
    

    希望这对其他人有所帮助。感谢@rolf82。

    【讨论】:

      猜你喜欢
      • 2019-03-05
      • 1970-01-01
      • 2013-09-30
      • 2021-08-02
      • 2017-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-26
      相关资源
      最近更新 更多