环境介绍只插入自定义字段(单条数据插入)只插入自定义字段(多条数据插入)
环境介绍① 环境说明
HIVE 2.1.0 + Hadoop 2.7.5
② 文章参考
HIVE INSERT 说明
只插入自定义字段(单条数据插入)① 非分区表的插入方式
-- 建表语句
create table if not exists user_card_info_temp
(
user_id string comment '用户ID',
user_name string comment '用户姓名',
card_id string comment '卡券ID',
card_name string comment '卡券名称'
)
comment '用户卡券明细表'
stored as orc tblproperties ('orc.compress'='SNAPPY')
;
-- 自定义字段插入格式
INSERT INTO TABLE tablename (COL_NAME1, COL_NAME2)
VALUES values_row [, values_row ...]
-- 插入语句示例,只插入 user_id、user_name 字段
INSERT INTO TABLE user_card_info_temp (user_id, user_name)
VALUES
('007','Jay')
;
② 分区表自定义字段的插入方式
-- 建表语句
create table if not exists card_info_temp
(
card_id string comment '卡券ID',
card_name string comment '卡券名称',
expire_time string comment '有效期',
start_time string comment '开始日期'
)
comment '卡券配置表'
partitioned by (ds string)
stored as orc tblproperties ('orc.compress'='SNAPPY')
;
-- 自定义字段插入格式
INSERT INTO TABLE tablename [PARTITION (partcol1[=val1], partcol2[=val2] ...)] (COL_NAME1, COL_NAME2)
VALUES values_row [, values_row ...]
-- 插入语句示例,只插入 user_id、user_name 字段
INSERT INTO TABLE card_info_temp partition(ds = '20220223') (card_id, card_name)
VALUES
('007','七日收益券')
;
只插入自定义字段(多条数据插入)
① 非分区表的插入方式
INSERT INTO TABLE user_card_info_temp (user_id, user_name)
VALUES
('008','kyle'), ('009','lisa'), ('010','jack')
;
② 分区表插入
INSERT INTO TABLE card_info_temp partition(ds = '20220223') (card_id, card_name)
VALUES
('008','高额收益券'),('009','免息收益券')
;



