You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GridDB Python执行Group By聚合查询时遭遇语法错误的问题求助

GridDB Python执行Group By聚合查询时遭遇语法错误的问题求助

最近我在一个项目里重新调研GridDB,现在需要做数据聚合操作,参考了官方的SQL语法指引来写查询语句,但试了好多次,不管是用常规的GROUP BY还是GROUP BY RANGE做聚合查询,都会报错。

先给大家看看我能正常运行的简单查询代码:

TABLE_NAME = "sensor_test_01"

conInfo = griddb.ContainerInfo(
    name=TABLE_NAME,
    column_info_list=[
        ["timestamp", griddb.Type.TIMESTAMP],
        ["sensor_id", griddb.Type.STRING],
        ["temperature", griddb.Type.DOUBLE],
        ["humidity", griddb.Type.DOUBLE]
    ],
    type=griddb.ContainerType.TIME_SERIES,
    row_key=True
)

ts = gridstore.put_container(conInfo)

query = ts.query("select * from "+TABLE_NAME+" limit 5")
try:
    rs = query.fetch(False)
    while rs.has_next():
        data = rs.next()
        print(data)
except griddb.GSException as e:
    for i in range(e.get_error_stack_size()):
        print("[", i, "]")
        print(e.get_error_code(i))
        print(e.get_message(i))

这段代码完全没问题,能成功打印出表中的前5条数据。

接下来是出问题的聚合查询代码:

# query = ts.query("select timestamp, avg(temperature) as temperature from "+TABLE_NAME+" GROUP BY RANGE timestamp EVERY (20,SECOND)")
query = ts.query("select sensor_id, avg(temperature) as temperature from "+TABLE_NAME+" GROUP BY sensor_id")
try:
    rs = query.fetch(False)
    while rs.has_next():
        data = rs.next()
        print(data)
except griddb.GSException as e:
    for i in range(e.get_error_stack_size()):
        print("[", i, "]")
        print(e.get_error_code(i))
        print(e.get_message(i))

不管是注释掉的那条用GROUP BY RANGE的语句,还是下面常规GROUP BY sensor_id的语句,执行时都会抛出语法错误,错误信息如下:

[151001:TQ_SYNTAX_ERROR_EXECUTION] Syntax error during parse

有没有小伙伴遇到过类似的问题,或者知道怎么解决吗?

备注:内容来源于stack exchange,提问作者dede kyuti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 16:33:02