标识符Identifiers

标识符是用于标识数据库对象(例如表、视图、架构或列)的字符串。An identifier is a string used to identify a database object such as a table, view, schema, or column. SQL Analytics 具有常规标识符和分隔标识符,它们均使用反引号引起来。SQL Analytics has regular identifiers and delimited identifiers, which are enclosed within backticks. 常规标识符和分隔标识符均不区分大小写。Both regular identifiers and delimited identifiers are case-insensitive.

语法Syntax

常规标识符Regular identifiers

{ letter | digit | '_' } [ , ... ]

分隔标识符Delimited identifiers

`c [ , ... ]`

参数Parameters

  • 字母:A-Z 或 a-z 中的任何字母。letter: Any letter from A-Z or a-z.
  • 数字:0 到 9 的任意数字。digit: Any numeral from 0 to 9.
  • c:字符集中的任何字符。c: Any character from the character set. 使用 ` 来转义特殊字符(例如 `.`)。Use ` to escape special characters (for example, `.`).

示例Examples

-- This CREATE TABLE fails with ParseException because of the illegal identifier name a.b
CREATE TABLE test (a.b int);
org.apache.spark.sql.catalyst.parser.ParseException:
no viable alternative at input 'CREATE TABLE test (a.'(line 1, pos 20)

-- This CREATE TABLE works
CREATE TABLE test (`a.b` int);

-- This CREATE TABLE fails with ParseException because special character ` is not escaped
CREATE TABLE test1 (`a`b` int);
org.apache.spark.sql.catalyst.parser.ParseException:
no viable alternative at input 'CREATE TABLE test (`a`b`'(line 1, pos 23)

-- This CREATE TABLE works
CREATE TABLE test (`a``b` int);