尝试在 GridDB 查询中使用特定时间范围获取时间序列数据时出错

问题描述 投票:0回答:1

我正在尝试从特定时间范围内的 TimeSeries 容器中获取数据。代码运行,但我收到一条错误,显示“'NOW'附近的语法错误”。这是我正在使用的 Python 代码:

from griddb_python import *

factory = StoreFactory.get_instance()
gridstore = factory.get_store(host="127.0.0.1", port=10001, cluster_name="myCluster", username="admin", password="admin")

# Access the container
container = gridstore.get_container("sensor_data")

# Query data within the last 24 hours
query = container.query("SELECT * WHERE timestamp > NOW() - INTERVAL '1 DAY'")
rs = query.fetch()

while rs.has_next():
    data = rs.next()
    print(data)

我需要帮助理解为什么 NOW() 函数不起作用以及我可以采取哪些措施来获取过去 24 小时的数据。我的查询语法有问题吗?

griddb
1个回答
0
投票

我认为错误是因为griddb不支持NOW()函数。在我看来,您应该计算当前时间戳,然后将其作为查询的一部分传递。您应该使用 python 的 datetime 函数来计算当前时间,然后从结果中减去 24 小时。我希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.