HIVE 自定义字段插入数据
环境介绍
① 环境说明
HIVE 2.1.0 + Hadoop 2.7.5
② 文章参考
只插入自定义字段(单条数据插入)
① 非分区表的插入方式
-- 建表语句
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','免息收益券')
;
版权声明:本文为hell_oword原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。