Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an empty copy of a table in hive

I have a table with lots of columns. I don't want to write something like

CREATE TABLE IF NOT EXISTS 
table1( 
col1 int, 
col2 String,
etc....)

Is there a fast way to create a table with the same structure, but without any data?

like image 960
gjin Avatar asked Jan 17 '17 12:01

gjin


1 Answers

Try this:

CREATE TABLE some_db.T1 LIKE some_db.T2

See this manual: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTableLike

like image 153
leftjoin Avatar answered Oct 12 '22 09:10

leftjoin