英文:
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
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论