Update hive column name

127 views Asked by At

I have a quick question about Hive DB.

If I have a table, lets say I created it by "CREATE EXTERNAL TABLE TEMP", with a certain location - and I want to change column names (only the name - not the type). If I'll run the same CREATE command, with different column names - what will happen? the table columns will update themselves? I'll get an error for "table already exists"?

I'm asking this, because I have the column names stored in a DB and I want to make an automatic process - so I don't want to write a specific "update column name" command...

Thanks!

2

There are 2 answers

0
sandeep rawat On

It can be done using ALTER TABLE table_name CHANGE As it needed meta change.

eg

ALTER TABLE table_name CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENT col_comment] [FIRST|AFTER column_name]

https://www.cloudera.com/documentation/enterprise/5-8-x/topics/impala_alter_table.html

0
Tanvir On

No, the table columns will not get updated. Instead, you'll get an error as table already exists.