hive sql 分区

创建分区表,以日期作为分区,一般先创建分区表,再插入数据

drop table if EXISTS t1;
create table t1(
    id      int
   ,name    string
   ,hobby   string
   ,add     string
)
partitioned by (pt_d string)
;

创建表t2,插入一行数据,待用,t2与t1表结构一样的,但是t2没有分区

drop table if EXISTS t2;
create table t2(
    id      int
   ,name    string
   ,hobby   string
   ,add     string
);
INSERT into t2 values(1, 'lang','hh', 'sdfd');

将t2数据插入到t1,分区日期是‘2018-10-27’,使用overwrite会删除之前分区所有内容,into将内容追加到分区
注意SELECT必须在同一行,不然我的编辑器会报错

INSERT overwrite TABLE t1 PARTITION(pt_d = '2018-10-27') SELECT * FROM t2;

你可能感兴趣的:(hive sql 分区)