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;
相关推荐
SelectDB15 小时前
Apache Doris 实战教程:手把手实现 ClickHouse 表结构迁移与数据校验
apache
SelectDB15 小时前
Apache Doris 实战教程:从零搭建 MCP Server,让 AI Agent 直接用自然语言查数据
apache
SelectDB15 小时前
Apache Doris Segment V3 宽表优化实战教程:从建表到体验元数据按需加载
apache
Database_Cool_21 小时前
云数据仓库开通指南:阿里云 AnalyticDB MySQL 10 分钟从 0 到分析实战教程
数据仓库·mysql·阿里云
java_logo21 小时前
Docker Compose 部署 Apache Superset:轻松搭建开源 BI 平台
docker·开源·apache·superset·轩辕镜像·superset部署方案·docker superset
Gent_倪2 天前
数据治理之元数据管理:Apache Atlas
apache
Kina_C2 天前
Apache HTTP Server 安装、配置与高级功能详解
linux·http·apache
中北marry2 天前
玄机靶场wp 第一章 日志分析-Apache日志分析
apache
java_logo2 天前
Apache Doris Docker 部署指南:实时分析数据库实战
数据库·docker·apache·doris·apache doris·轩辕镜像·docker部署doris
罗政3 天前
基于AI工作流的多渠道销售数据仓库清洗统计实践
数据仓库