修改

列的名称、类型、位置、注释

hive>ALTER TABLE t3 CHANGE COLUMN old_name new_name String [COMMENT '...'] [AFTER column2];


实例

hive (zmgdb)> alter table t1 change column car sarly int after office;
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Unable to alter table. The following columns have types incompatible with the existing columns in their respective positions :
sarly

----字段car是string类型与int类型不兼容,不能强转。


hive (zmgdb)> alter table t1 change column car sarly string after office;
OK
Time taken: 0.132 seconds
hive (zmgdb)> desc t1;
OK
col_name        data_type       comment
name                    string                                      
address                 string                                      
company                 string                                      
office                  string                                      
sarly                   string                                      
Time taken: 0.035 seconds, Fetched: 5 row(s)
hive (zmgdb)> 

意思是:修改car字段为sarly字段,位置放在office字段后面。

增加

hive>ALTER TABLE t3 ADD COLUMNS(gender int);
columns:复数,可以多个


没有删除列的命令:
删除列后,会导致数据解析出问题



Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐