Skip to main content
techshaj
Silver ⭐️
Apr 24, 2019 6:01 AM UTC
Solved

How can we change the column order in Hive table without deleting data.

I need to change the column order in a Hive table, but I want to make sure I can do it without deleting any of the existing data.

Szczechla
SzczechlaAnswer
Gold ⭐️
Apr 24, 2019 9:42 PM UTC

Hi,

 

This command moves column_name after column_name2:

alter table table_name change column column_name column_name column_name_type after column_name2;

 

You have to put the column_name twice (or you can change column name) and type of the column.

 

Regards

Andrzej

5 replies

Szczechla
SzczechlaAnswer
Gold ⭐️
Apr 24, 2019 9:42 PM UTC

Hi,

 

This command moves column_name after column_name2:

alter table table_name change column column_name column_name column_name_type after column_name2;

 

You have to put the column_name twice (or you can change column name) and type of the column.

 

Regards

Andrzej

Translate
shivani99
Silver ⭐️
Nov 30, 2022 2:40 PM UTC

In this solution, we are able to change position of a single column. Is it possible to change positions of 2 or more consecutive columns in the same way ?

Translate
EricL
Platinum ⭐️⭐️
Platinum ⭐️⭐️
May 8, 2019 4:35 AM UTC
If you change column order, it will affect existing data, so the new position of the column will match different data, that's OK for you?
Translate
techshaj
techshajAuthor
Silver ⭐️
May 10, 2019 1:27 AM UTC

That's ok

Translate