31-数据仓库与Apache Hive-Insert插入数据

1.Insert语法功能

复制代码
 1.1 暴力方式上传
 1.2 使用 hadoop fs -put 方式上传 
 1.3. 使用load 加载数据 !!! 

hive 官方推荐第三种方式 !!!

复制代码
	基于上图  在hive中 insert into table values... 这样的语法禁止使用!
	推荐使用:
	INSERT INTO TABLE tablename select_statement1 FROM from_statement;
  insert +select 表示:
    将后面的查询结果作为内容插入到指定的表中.
    注意事项:
     1.需要保证查询结果列的数目和需要插入的数据表的列的数据一致
     2.如果查询出来的数据类型和拆入表的数据类型不一致,将会进行转换,但是不能保证转换一定成功[ string  int ],转换失败的数据会为null <注意数据类型要一致>
     INSERT INTO TABLE tablename select_statement1 FROM from_statement;
bash 复制代码
-- 2025年08月08日
show databases ;
show schemas ;

show tables ;
--新建数据库
create  database shaonainai;

-- 用一下库
use shaonainai;

-- 本地上传表
create table student_local(
  num int,
  name string,
  sex string,
  age int ,
  dept string

) row format delimited
fields terminated by ',';


create table student_hdfs(
  num int,
  name string,
  sex string,
  age int ,
  dept string

) row format delimited
fields terminated by ',';




load data local inpath '/export/data/hivedata/students.txt' into table shaonainai.student_local;


load data  inpath '/students.txt' into table shaonainai.student_hdfs;


select * from student_hdfs;

-- 讲解  INSERT INTO TABLE tablename select_statement1 FROM from_statement;

create table student(
  num int,
  name string,
  sex string,
  age int ,
  dept string

) row format delimited
fields terminated by ',';

-- 加载数据
load data local inpath '/export/data/hivedata/students.txt' into table shaonainai.student;

select  * from student;

--  新建两列的表 等待数据插入
create table student_from_insert(
  num int,
  name string
) ;


select * from student_from_insert;
-- 语法   INSERT INTO TABLE 要插入数据的表 select 列名1,列名2... FROM 有数据的表;
 INSERT INTO TABLE student_from_insert select num,name  FROM student;

select * from student_from_insert;
相关推荐
十月南城7 天前
数据湖技术对比——Iceberg、Hudi、Delta的表格格式与维护策略
大数据·数据库·数据仓库·hive·hadoop·spark
王九思7 天前
Hive Thrift Server 介绍
数据仓库·hive·hadoop
土拨鼠烧电路7 天前
笔记11:数据中台:不是数据仓库,是业务能力复用的引擎
数据仓库·笔记
Asher05098 天前
Hive核心知识:从基础到实战全解析
数据仓库·hive·hadoop
xhaoDream8 天前
Hive3.1.3 配置 Tez 引擎
大数据·hive·tez
james的分享8 天前
大数据领域核心 SQL 优化框架Apache Calcite介绍
大数据·sql·apache·calcite
莫寒清8 天前
Apache Tika
java·人工智能·spring·apache·知识图谱
归叶再无青8 天前
web服务安装部署、性能升级等(Apache、Nginx)
运维·前端·nginx·云原生·apache·bash
忙碌5449 天前
OpenTelemetry实战指南:构建云原生全链路可观测性体系
ios·flink·apache·iphone