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 小时前
Apache Maven 鸿蒙 PC 适配全记录:把 JVM 构建工具交付到 HiShell
maven·apache·harmonyos
网络豆10 小时前
Apache Hive 鸿蒙 PC 适配全记录:以 Qt 客户端打通 HiveQL、监控与元数据访问
hive·apache·harmonyos
网络豆10 小时前
Apache HBase 鸿蒙 PC 适配全记录:用 Qt 原生客户端打通 REST 管理与数据读写
apache·hbase·harmonyos
无巧不成书02181 天前
Apache Tomcat 9 下载全指南(Windows,Linux,macOS):版本选型、国内镜像、SHA-512 与 PGP 完整性校验
windows·tomcat·apache
fastjson_1 天前
Hive3.1.3 安装使用
hive
Dream-Y.ocean1 天前
鸿蒙平台 Apache Tomcat 管理控制台适配实战:基于 Electron 壳方案的真实 HTTP 服务器实现
tomcat·apache·harmonyos
betazhou1 天前
Apache seatunel常用配置参数解析说明
apache·seatunnel
宽海智能仓储物流2 天前
航发自动化立体库异构系统改造:宽海智能30天联调技术全解析
运维·数据仓库·自动化
凤山老林2 天前
Spring Boot 集成 Apache Kafka Streams 构建流处理应用:状态存储、窗口聚合与
spring boot·kafka·apache
DolphinScheduler社区3 天前
Apache DolphinScheduler 8 月报:权限安全加固,调度补火上线,性能与稳定性持续提升
大数据·安全·开源·apache·任务调度·海豚调度