I have come across a problem in a snowflake,
Query:
select 'name' as Name from profile
which returns the output as:
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
Name
______________
Ram
Kishore
Rohit............
How will I remove the single quote in the select statement for the column name? 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
CodePudding user response:
'name'
is a string, thus a constant, and why it is on every line.
a column name
would ether be referenced with no quotes, or via double quotes "name"
. But thus implies there is a column called 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). 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
CodePudding user response:
You can try using the IDENTIFIER function, which has examples at the bottom of the below page:
https://docs.snowflake.com/en/sql-reference/identifier-literal.html
Your example will look like:
select identifier('name') as Name from profile;