sqlgriddb

GridDB SQL queries fail with [100009] Syntax error when using TIMESTAMP ranges


I'm trying to fetch data from a GridDB TimeSeries container within a specific time range, but my SQL queries keep failing with an error

[100009] Syntax error

For example, this Python code:

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")
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()

This results in an error

[100009] Syntax error

I expected this query to return all rows from the last 24 hours. Not sure what is the issue.


Solution

  • You are using MySQL syntax. For GridDB the syntax is (as per the documentation) as follows:

    SELECT *
    WHERE timestamp > TIMESTAMP_ADD(DAY, NOW(), -1);