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;
相关推荐
AM越.9 小时前
助睿:!!零代码解决!!订单利润分流数据加工o(* ̄▽ ̄*)ブ
数据仓库·笔记·etl·助睿
juniperhan2 天前
Flink 系列第24篇:Flink SQL 集成维度表指南:存储选型、参数调优与实战避坑
大数据·数据仓库·sql·flink
隐于花海,等待花开2 天前
41.ABS / POW / SQRT 函数深度解析
大数据·hive
RestCloud2 天前
ETL数据质量保障:如何通过优化提升数据准确性?
数据仓库·etl·数据处理·数据传输·数据同步·数据集成平台
运维全栈笔记2 天前
Linux安装配置Tomcat保姆级教程:从部署到性能调优
linux·服务器·中间件·tomcat·apache·web
隐于花海,等待花开2 天前
40.RAND 函数深度解析
hive·hadoop
❀͜͡傀儡师2 天前
Apache Doris 4.0.0 存算分离手动部署指南
apache·doris 4.0
2501_927283583 天前
荣联汇智助力天津艺虹打造“软硬一体”智慧工厂,全流程自动化引领印刷包装行业数智变革
大数据·运维·数据仓库·人工智能·低代码·自动化
孤雪心殇3 天前
快速上手数仓基础知识
数据仓库·hive·spark
渣渣盟3 天前
数据仓库 vs 数据湖 vs 湖仓一体:架构演进与选型
数据仓库·架构