識別子
説明
識別子は、テーブル、ビュー、スキーマ、カラムなどのような、データベースオブジェクトを識別するために使われる文字列です。Spark SQL には通常の識別子と区切られた識別子があり、これらはバックティックで囲まれています。通常の識別子と区切られた識別子はどちらも大文字と小文字を区別しません。
構文
通常の識別子
{ letter | digit | '_' } [ , ... ]
注意: spark.sql.ansi.enabled
が true に設定された場合、ANSI SQL 予約キーワードは識別子として使うことができません。詳細については、ANSI 準拠 を参照してください。
区切られた識別子
`c [ ... ]`
パラメータ
-
文字
A-Z または a-z からの任意の文字。
-
桁
0から9までの任意の数字。
-
c
文字セットの任意の文字。特殊文字をエスケープするには、
`
を使います (例えば`
)。
例
-- 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);