By default, unquoted identifiers are case-insensitive and must begin with either a letter or the underscore (
_) character. In addition, they can only contain a combination of standard
alphanumeric characters and symbols.
To support case-sensitive identifiers, as well as allowing identifiers to start with special characters and use extended characters (including blank spaces), identifiers can be enclosed in double quotes.
- Regardless of whether an identifier is unquoted or double-quoted, the maximum number of characters allowed is 256 (including blank spaces).
- Identifiers can also be specified using string literals, session variables or bind variables. For details, see SQL Variables.
In this Topic:
Unquoted Identifier Examples¶
The following are all examples of valid identifiers; however, the case of the characters in these identifiers would not be preserved:
myidentifier MyIdentifier1 My$identifier _my_identifier
Identifiers enclosed by double quotes are case-sensitive and can start with and contain any valid characters, including:
- Special characters (
- Extended ASCII and non-ASCII characters
- Blank spaces
"Identifier" "3_identifier" "$Identifier" "My Identifier" "идентификатор"
If an object is created using a double-quoted identifier, when referenced in a query or any other SQL statement, the identifier must be specified exactly as created, including the double
quotes. Failure to include the quotes may result in an
Object does not exist error (or similar type of error).
By default, Snowflake applies the following rules for storing identifiers (at creation/definition time) and resolving them (in queries and other SQL statements):
When an identifier is unquoted, it is stored and resolved in uppercase. For example, the following names are equivalent and all resolve to
COLUMNNAME columnname columnName ColumnName
When an identifier is double-quoted, it is stored and resolved exactly as entered, including case. For example, the following are treated as four different, unique values:
"COLUMNNAME" "columnname" "columnName" "ColumnName"
If these identifiers were used to create objects of the same type (e.g. tables), they would result in the creation of four distinct objects.
Third-party Tools and Case-insensitive Identifier Resolution¶
Some third-party applications always use double quotes for identifiers in the SQL queries they generate, which may result in queries containing identifiers that cannot be found in Snowflake due to differences in case.
Controlling Case Using the QUOTED_IDENTIFIERS_IGNORE_CASE Parameter¶
To prevent this situation from occurring, Snowflake provides a session parameter, QUOTED_IDENTIFIERS_IGNORE_CASE, that ensures all alphabetical characters in identifiers created within the session are stored in uppercase, regardless of whether the identifier is double-quoted. The default for the parameter is FALSE.
To modify the case-sensitive behavior for double-quoted identifiers, set the parameter to TRUE for the session. Thereafter, all alphabetical characters in identifiers are stored in uppercase.
In other words, the following would all be equivalent:
COLUMNNAME columnname columnName ColumnName "COLUMNNAME" "columnname" "columnName" "ColumnName"
Note that the parameter does not impact any of the limitations for unquoted identifiers with regards to numbers, special characters, and blank spaces.
Impact of Changing the Parameter¶
Changing the QUOTED_IDENTIFIERS_IGNORE_CASE session parameter only affects new objects and queries:
- With the default setting of FALSE, if an object is created using a double-quoted identifier with mixed case, Snowflake stores the identifier in mixed case.
- If the parameter is then changed to TRUE, the identifier for the newly-created object is not retrievable/resolvable.
Due to the impact that changing the parameter can have on resolving identifiers, we highly recommend choosing an identifier resolution method early in your implementation of Snowflake and then dictating the default behavior by setting the parameter at the account level accordingly, which can be done by any account administrator for your account. The parameter can always be overridden at the session level, but we don’t encourage changing the parameter from the default, unless you have an explicit need to do so.
The following examples illustrate the behavior after changing the parameter from FALSE to TRUE:
-- Set the default behavior ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = false; -- Create a table with a double-quoted identifier CREATE TABLE "One" (i int); -- stored as "One" -- Create a table with an unquoted identifier CREATE TABLE TWO(j int); -- stored as "TWO" -- These queries work SELECT * FROM "One"; -- searches for "One" SELECT * FROM two; -- searched for "TWO" SELECT * FROM "TWO"; -- searches for "TWO" -- These queries do not work SELECT * FROM One; -- searches for "ONE" SELECT * FROM "Two"; -- searches for "Two" -- Change to the all-uppercase behavior ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = true; -- Create another table with a double-quoted identifier CREATE TABLE "Three"(k int); -- stored as "THREE" -- These queries work SELECT * FROM "Two"; -- searches for "TWO" SELECT * FROM two; -- searched for "TWO" SELECT * FROM "TWO"; -- searches for "TWO" SELECT * FROM "Three"; -- searches for "THREE" SELECT * FROM three; -- searches for "THREE" -- This query does not work now - "One" is not retrievable SELECT * FROM "One"; -- searches for "ONE"
Additionally, if the identifiers for two tables differ only by case, one identifier might resolve to a different table after changing the parameter:
-- Set the default behavior ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = false; -- Create a table with a double-quoted identifier CREATE TABLE "Tab" (i int); -- stored as "Tab" -- Create a table with an unquoted identifier CREATE TABLE TAB(j int); -- stored as "TAB" -- This query retrieves "Tab" SELECT * FROM "Tab" -- searches for "Tab" -- Change to the all-uppercase behavior ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = true; -- This query retrieves "TAB" SELECT * FROM "Tab" -- searches for "TAB"