copy data from one partitioned table to another new partitioned table

Viewed 18

Need to copy data from one partitioned table to another new partitioned table tried this method but doesn't work

create table if not exists box_db.table_1 partitioned by (sch_ky, at_ky, date) as select * from sand_db.table_2

Also tried

create table box_db.table_1 (id bigint, sch_val int, at_val int) partitioned by (sch_ky int, at_ky int, date string)

and insert data into it

insert into box_db.table_1 select * from sand_db.table_2

but both doesn't work

1 Answers

create the table with new partition values. Then to insert into a partitioned table, you need to -

  1. mention partition column if you are inserting in table with dynamic partition.
insert into box_db.table_1 partition(id, sch_val, at_val) select ..., id,sch_val, at_val from sand_db.table_2 -- make sure  last columns matches to last columns in select clause

or 2. mention partition value if you are inserting in table with static partition.

insert into box_db.table_1 partition(id=1, sch_val=2, at_val=3) select ...  from sand_db.table_2 -- make sure  all columns in select matches to the columns in table
Related