简体   繁体   English

删除雪花中列名上的单引号

[英]Removing single quotes on a column name in snowflake

I have come across a problem in a snowflake,我在雪花中遇到了一个问题,

Query:询问:

select 'name' as Name from profile

which returns the output as:它将 output 返回为:

Name
________
name

name

name

name
.........

What I actually need is我真正需要的是

select name as Name from profile

which will return the correct output which I expect as这将返回我期望的正确的 output

Name
______________
Ram

Kishore

Rohit............

How will I remove the single quote in the select statement for the column name?如何删除列名的 select 语句中的单引号? I know its simple to just remove the single quote from name but my problem is that the name is a variable passed in a function and it is a varchar我知道从名称中删除单引号很简单,但我的问题是名称是在 function 中传递的变量,它是一个 varchar

'name' is a string, thus a constant, and why it is on every line. 'name'是一个字符串,因此是一个常量,以及为什么它出现在每一行。

a column name would ether be referenced with no quotes, or via double quotes "name" .name不带引号或通过双引号"name"引用。 But thus implies there is a column called name.但这意味着有一个名为 name 的列。

by default in Snowflake all tokens are case in sensitive if not double quouted as they are case to upper case, where as the tokens in double quotes are not projected to upper case form (unless the option to ignore case of double quoted names is on).默认情况下,在 Snowflake 中,如果不是双引号,则所有标记都区分大小写,因为它们是从大小写转换为大写的,其中双引号中的标记不会投影为大写形式(除非启用了忽略双引号名称大小写的选项) . So if you are directly want the name cloumn to be output as Name then you will need to use name as "Name" to avoid it becoming NAME因此,如果您直接希望名称 cloumn 为 output 作为Name ,那么您需要使用name as "Name"以避免它成为NAME

You can try using the IDENTIFIER function, which has examples at the bottom of the below page:您可以尝试使用 IDENTIFIER function,下面页面底部有示例:

https://docs.snowflake.com/en/sql-reference/identifier-literal.html https://docs.snowflake.com/en/sql-reference/identifier-literal.html

Your example will look like:您的示例将如下所示:

select identifier('name') as Name from profile;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM