hive表增加字段,並指定字段位置


方法:
先增加字段,然后再移動字段。

alter table tbl_1 add columns(col_c string comment'ccc') ;
alter table tbl_1 change col_c col_c string comment'cccc' after col_b;

具體代碼如下:

1. 創建表
create table tbl_1(
  col_a string comment'aaa'
, col_b string comment'bbb'
, col_d string comment'ddd'
) comment'test'
;

查看表結構
desc tbl_1 ;

順序:
a
b
d

2. 增加字段
alter table tbl_1 add columns(col_c string comment'ccc') ;

查看表結構
desc tbl_1 ;

順序:
a
b
d
c

3. 移動新增的字段
alter table tbl_1 change col_c col_c string comment'cccc' after col_b;

查看表結構
desc tbl_1 ;

順序:
a
b
c
d


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM