INSERT

INSERT 用于在表中插入新行。

语法描述

INSERT 用于在表中插入新行。

语法结构

> INSERT INTO [db.]table [(c1, c2, c3)] VALUES (v11, v12, v13), (v21, v22, v23), ...

Iceberg INSERT OVERWRITE

INSERT OVERWRITE 支持映射 Apache Iceberg 表的外部表,用于替换本次写入覆盖范围内的行。可选的 PARTITION 子句用于指定静态 Iceberg 分区,必须包含一个或多个不重复的分区字段及字面量值。该子句不支持表达式、子查询或普通表的分区名称语法。对普通表和非 Iceberg 外部表使用 INSERT OVERWRITE 或基于值的 PARTITION 会被拒绝。

INSERT OVERWRITE [INTO] iceberg_table
    [PARTITION (field = literal [, field = literal ...])]
    SELECT ...;
INSERT OVERWRITE iceberg_orders
    SELECT order_id, region, amount FROM staging_orders;

INSERT OVERWRITE iceberg_orders
    PARTITION (region = 'us-east-1', day = 20260827)
    SELECT order_id, region, amount FROM staging_orders;

示例

drop table if exists t1;
create table t1(a int default (1+12), b int);
insert into t1(b) values(1), (1);

mysql> select * from t1;
+------+------+
| a    | b    |
+------+------+
|   13 |    1 |
|   13 |    1 |
+------+------+
2 rows in set (0.01 sec)

drop table if exists t1;
create table t1 (a date);
insert into t1 values(DATE("2017-06-15 09:34:21")),(DATE("2019-06-25 10:12:21")),(DATE("2019-06-25 18:20:49"));

mysql> select * from t1;
+------------+
| a          |
+------------+
| 2017-06-15 |
| 2019-06-25 |
| 2019-06-25 |
+------------+
3 rows in set (0.00 sec)

drop table if exists t;
CREATE TABLE t (i1 INT, d1 DOUBLE, e2 DECIMAL(5,2));
INSERT INTO t VALUES ( 6, 6.0, 10.0/3), ( null, 9.0, 10.0/3), ( 1, null, 10.0/3), ( 2, 2.0, null );

mysql> select * from t;
+------+------+------+
| i1   | d1   | e2   |
+------+------+------+
|    6 |    6 | 3.33 |
| NULL |    9 | 3.33 |
|    1 | NULL | 3.33 |
|    2 |    2 | NULL |
+------+------+------+
4 rows in set (0.01 sec)