Python Influx查询在查询中插入日期

时间:2019-12-03 10:51:31

标签: python influxdb

当我运行以下语句查询流入时,出现错误:

  

InfluxDBClientError:无效的时间戳字符串

date_from  = '2019-12-02 T00:00:00Z'
date_to = '2019-12-02T01:00:00Z'
"""SELECT "value" FROM "location/PRESSURE_SENSOR_1" WHERE time >= """ + '\'' + date_from + '\'' + """ and time <= '2019-12-02T01:00:00Z' """

如果我运行以下命令,它将正常工作:

client.query("""SELECT "value" FROM "location/PRESSURE_SENSOR_1" where time >= '2019-10-02 00:00:00' and time < '2019-10-03 00:00:00'"""))

目标是建立一个语句,我可以在其中插入变量,但我不希望这样做。任何帮助表示赞赏吗? 谢谢

1 个答案:

答案 0 :(得分:1)

您应该在api中利用bind_params完成此任务。

query = "SELECT value FROM 'location/PRESSURE_SENSOR_1' where time >= $start_time and time < $end_time"
bind_params = {'end_time': '2019-10-03 00:00:00', 'start_time': '2019-10-02 00:00:00'}
client.query(query, bind_params=bind_params))

在此处查找更多信息: Influx Client Documenation