如何用select语句查询字段名是以特殊字符或者数字开头的字段

server版本:2.00.8 2022.09.28

以下pivod by操作产生的列名的列名是按照pivod by之前的原始字段内容产生,会出现以数字开头或者中间包含空格的字段名

date = take(2021.08.01  2021.08.02 2021.08.03, 12)
sym = take(["IBM N", "_MSFTN", "3_GOOGS", ""], 12).sort()
value = 1..12
t=table(date, sym, value)
re = select value from t pivot by date, sym

attachments-2023-01-12DnZ1NL63c90d640df8b.png

之后再对上述结果表re做select查询时报错 Can't recognize token 3_GOOGS' 请问这种列名,脚本要写才能怎么取呢?

select 3_GOOGS  from re

attachments-2023-01-2gykSUDt63c90f12ed723.png

请先 登录 后评论

1 个回答

Yating Xie

包含特殊符号或以数字开头的列名在 SQL 中引用时,需将列名用双引号引用,并在其之前使用下划线作为标识,例如:_"IBM.N", _"000001.SH"。

您的脚本改为以下写法,可正确执行:

select _"3_GOOGS"  from re

attachments-2023-01-jlMUHgM363c90e4f4fc0f.png

参考链接:https://www.dolphindb.cn/cn/help/200/SQLStatements/pivotBy.html

请先 登录 后评论