Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to alter column type in hive table?

Tags:

metadata

hive

The current schema is:

hive> describe tableA; OK id      int ts      timestamp 

I want to change ts column to be BIGINT without dropping table and recreate again. Is it possible?

like image 235
interskh Avatar asked Jul 05 '13 22:07

interskh


People also ask

How do I change the datatype of multiple columns in Hive?

Refer to the command below: hive> ALTER TABLE <tablename> REPLACE COLUMNS (<old column name> INT, <new column name> STRING); This command will only change the schema of the table i.e., it will change the column name and the datatype but will not affect the data stored in the column.

Which command is used to modify column data type in the table?

The SQL ALTER TABLE command is used to add, delete or modify columns in an existing table.

Can we alter Hive table?

In Hive, we can perform modifications in the existing table like changing the table name, column name, comments, and table properties. It provides SQL like commands to alter the table.


2 Answers

Found the solution:

ALTER TABLE tableA CHANGE ts ts BIGINT AFTER id; 

See this for complete details: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterColumn

like image 94
interskh Avatar answered Oct 19 '22 17:10

interskh


ALTER TABLE table_name CHANGE col_name col_name newType 
like image 25
Animesh Raj Jha Avatar answered Oct 19 '22 18:10

Animesh Raj Jha