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

TDengine执行SQL报错‘Invalid tbname pseudo column’,请求排查语法问题

问题排查与解决方案

错误原因分析

报错Invalid tbname pseudo column由两个核心问题导致:

  1. partition by ts语法位置错误:TDengine中partition by是超级表专属查询子句,只能直接跟在超级表名称后,不能用于子查询的结果集。
  2. 伪列tbname的引用问题:子查询使用select *时,虽会包含tbname,但子查询结果集属于普通数据集,会丢失tbname作为超级表伪列的特性,导致后续分组聚合时无法被正确识别。

修正后的SQL语句

方案一:去掉冗余子查询(推荐)

直接在超级表后使用partition by,简化语句逻辑:

select task_name, group_concat(tbname, ',') as job
from meters 
partition by ts 
where ts >= '2022-11-03 10:10:00' and tenant_name = 'xxx'
group by task_name 
having max(cpu) > 100;

方案二:保留子查询并显式指定字段

如果必须使用子查询,需显式指定所需字段(包括tbname),并将partition by移到超级表查询处:

select task_name, group_concat(tbname, ',') as job
from (
    select task_name, tbname, cpu, ts 
    from meters 
    partition by ts 
    where ts >= '2022-11-03 10:10:00' and tenant_name = 'xxx'
) 
group by task_name 
having max(cpu) > 100;

内容的提问来源于stack exchange,提问作者JamesLiu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 10:01:22