3

Can I change the datatype in Hive database? Below is a complete information about the same.

I have a database named "test". It has a table "name". Below is a query I had used while creating a column in name table.

create table name(custID String,nameValuePairs array<struct< key:String, value:String>>) row format delimited fields terminated by '/' collection items terminated by '|' map keys terminated by '=' lines terminated by '\n';

Now, I would like to change the datatype entry of column name "nameValuePairs".

Currently the column nameValuePairs has datatype array<struct< key:String, value:String>>.

Now I would like to change the datatype to array<struct< something:somedatatype, value:String>>.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Nitesh B.
  • 563
  • 2
  • 7
  • 20

1 Answers1

2

You need to use the following ALTER TABLE syntax:

ALTER TABLE table_name CHANGE column_name column_name newType

To break it down, you are:

  • Making a change to the table: ALTER TABLE
  • Defining what table you are changing: table_name
  • Defining what column you will change: CHANGE column_name
  • Defining the change (you can also change column_name hence the double mention): column_name newType
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
I_GNU_it_all_along
  • 1,702
  • 13
  • 20