HIVE带中括号的列名取数

发布时间 2023-08-15 10:28:05作者: 何辉煌

某次取数,某表中有奇怪的字段名:pointchange_ygz_[yyyy],带了个中插号,用简单查询出错

select
  pointchange_ygz_[yyyy] as p
from
  t

出错信息:

Error while compiling statement: FAILED: SemanticException [Error 10004]: 
Line 1:7 Invalid table alias or column reference 'pointchange_ygz_': (possible column names are: ……

不论在该字段名加单引号,双引号,反单引号,还是什么斜杠、反斜杠,统统不行。后来茂名黄工指出用这样的语法即可解决:

set hive.support.quoted.identifiers=none;
select `pointchange_ygz_[yyyy]` as p from t;

注意列名还是要用反单引号括起来,否则还是不行。

hive.support.quoted.identifiers 应该是指查询时正则表达式的内容。