[Python] How to perform range queries on TIMESTAMP fields in GridDB Cloud using the Python...

Discussão em 'Python' iniciado por Stack, Junho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using GridDB Cloud and the Python client (griddb_python) to build a time-series dashboard. The goal is to retrieve rows from a container called sensor_data where the created_at timestamp is within a given date range.

    Goal :

    I want to query all rows from sensor_data where created_at is between '2023-01-01T00:00:00Z' and '2024-01-01T00:00:00Z'. These rows are used to generate analytics based on time periods.

    Example Data Inserted :

    container.put(["id_001", datetime(2023, 5, 1, 10, 0), 45.5])
    container.put(["id_002", datetime(2023, 6, 15, 14, 30), 42.1])
    container.put(["id_003", datetime(2024, 2, 1, 9, 45), 47.3]) # should be excluded


    Container schema confirmed via container.get_column_info():

    [
    ['id', ColumnType.STRING],
    ['created_at', ColumnType.TIMESTAMP],
    ['temperature', ColumnType.DOUBLE]
    ]


    Query Code

    query = container.query(
    `"SELECT * WHERE created_at >= TIMESTAMP('2023-01-01T00:00:00Z') "
    "AND created_at <= TIMESTAMP('2024-01-01T00:00:00Z')"
    )
    rs = query.fetch()

    for row in rs:
    print(row)


    Problem :

    The query executes without any error, but returns an empty result set — even though two of the inserted rows match the range.

    There are:


    • No GSException errors


    • No warnings

    Just no rows returned

    I confirmed that the timestamps were inserted using Python’s datetime object, and the container was created as a COLLECTION, not a TIME_SERIES.

    My Questions Is the TIMESTAMP format in the TQL query correct? Does GridDB require a specific format (e.g., no Z, no colons) for TIMESTAMP in string form? Are additional steps needed to index or cast timestamp fields? Is there a difference in how COLLECTION and TIME_SERIES containers handle timestamp filtering?

    Environment :


    • GridDB Cloud (Free Plan)


    • Python 3.10


    • griddb_python client

      Container type: COLLECTION

      Schema: id (STRING), created_at (TIMESTAMP), temperature (DOUBLE)

    Continue reading...

Compartilhe esta Página