Search code examples
pythoniotgriddb

GridDB TQL Invalid Column


I'm currently working with GridDB for a project involving IoT data, and I'm facing an issue with executing SQL-like queries using GridDB's TQL (Time Series SQL-like Query Language).

Here is a brief description of what I am trying to achieve:

I have a container in GridDB which stores IoT sensor data. I am trying to query this data using TQL to fetch records based on certain conditions. Here is a sample of my container schema and the data insertion code:

import griddb_python as griddb

factory = griddb.StoreFactory.get_instance()
gridstore = factory.get_store(
    host='127.0.0.1', 
    port=10001, 
    cluster_name='defaultCluster', 
    username='admin', 
    password='admin'
)

# Define container schema
conInfo = griddb.ContainerInfo(
    name="sensorData",
    column_info_list=[
        ["TimeStamp", griddb.Type.TIMESTAMP],
        ["Sensor_id", griddb.Type.STRING],
        ["Value", griddb.Type.DOUBLE]
    ],
    type=griddb.ContainerType.TIME_SERIES,
    row_key=True
)

# Create container
ts = gridstore.put_container(conInfo)
ts.set_auto_commit(False)

# Insert sample data
import datetime
ts.put([datetime.datetime.now(), "sensor_1", 25.5])
ts.put([datetime.datetime.now(), "sensor_2", 26.7])
ts.commit()

Now, I am trying to execute the following TQL query to fetch records:

query = ts.query("SELECT * FROM sensorData WHERE value > 26")
rs = query.fetch()

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

Im getting the following error though:

InvalidColumnException: Column (value) not found

I've checked the schema and value exists so i'm not sure if it is talking about some other column or something wrong with value exactly? Any help would be appreciated.


Solution

  • By default, SQL column names are case insensitive in some languages like MYSQL. TQL is case sensitive though.

    change value to Value:

    query = ts.query("SELECT * FROM sensorData WHERE Value > 26")