我有一个像这样的Hive表:
CREATE TABLE mytest (name int, timestamp bigint, donation int);
我使用的是Hive 0.12。请注意字段“timestamp”。顺便提一下,Hive 0.12+引入了一种名为timestamp
的新数据类型。假设我想将此字段重命名为time_stamp
我试过这些:
ALTER TABLE mytest CHANGE timestamp time_stamp BIGINT;
ALTER TABLE mytest CHANGE COLUMN timestamp time_stamp BIGINT;
ALTER TABLE mytest CHANGE [timestamp] time_stamp BIGINT;
ALTER TABLE mytest CHANGE `timestamp` time_stamp BIGINT;
然而,所有这些都给我以下错误:
FAILED: ParseException line 1:38 mismatched input 'CHANGE' expecting KW_EXCHANGE near 'mytest' in alter exchange partition
我确定这是因为我的字段名称与数据类型名称相同。如何更改mytest
的架构,而不必执行以下操作?
CREATE mytest_cpy AS SELECT mytest.name, mytest.timestamp AS time_stamp,
mytest.donation FROM mytest;
DROP TABLE mytest;
ALTER TABLE mytest_cpy RENAME TO mytest;
谢谢!任何/所有帮助表示赞赏!
答案 0 :(得分:2)
对任何包含奇怪符号或与数据类型相同的异常列名称使用反引号。这适用于Hive 0.14:
ALTER TABLE mytest CHANGE COLUMN `timestamp` time_stamp BIGINT;
答案 1 :(得分:0)
在MS SQL中使用:
EXECUTE sp_rename 'dbo.mytest.timestamp', 'time_stamp', 'COLUMN'
在MYSQL中的尝试:
USE database_name;
ALTER TABLE mytest CHANGE timestamp time_stamp BIGINT;
或:
ALTER TABLE database_name.mytest CHANGE timestamp time_stamp BIGINT;
答案 2 :(得分:0)