使用DolphinDB的SQL语句查询包含特殊字符或以数字开头的列。

huangapple go评论77阅读模式
英文:

Query columns containing special characters or starting with digits with SQL statement in DolphinDB

问题

Server version: 2.00.8 2022.09.28

我在DolphinDB中使用pivot by获取了一个名为re的表,并生成的列名包含特殊字符。

当我使用select语句查询表re时,

查询3_GOOGS from re

出现错误消息“无法识别令牌3_GOOGS”。如何修复这个查询?

英文:

Server version: 2.00.8 2022.09.28

I obtain a table re with pivot by in DolphinDB and the generated column names contain special characters.

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

使用DolphinDB的SQL语句查询包含特殊字符或以数字开头的列。

When I query table re with a select statement,

select 3_GOOGS  from re

An error message “Can't recognize token 3_GOOGS“ is raised. How can I fix the query?

答案1

得分: 1

当在SQL语句中使用包含特殊字符或以数字开头的列名时,它们应该用双引号括起来,并在DolphinDB中使用下划线作为标识符。例如:"IBM.N","000001.SH"。因此,您的查询可以修改为:

select _"3_GOOGS" from re
英文:

When column names containing special characters or starting with digits are used in SQL statements, they should be enclosed in double quotes and use an underscore as an identifier before it in DolphinDB. For example: _”IBM.N”, _”000001.SH”. So your query can be modified as:

select _"3_GOOGS" from re

huangapple
  • 本文由 发表于 2023年2月8日 09:40:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75380622.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定