云数据库 GaussDB-导入最佳实践:使用INSERT批量插入

时间:2023-11-01 16:22:49

使用INSERT批量插入

带SELECT子句使用批量插入操作来实现高性能数据插入。

如果需要将数据或数据子集从一个表移动到另一个表,可以使用INSERTCREATE TABLE AS 命令。

如果从指定表插入数据到当前表,例如在数据库中创建了一个表customer_t1的备份表customer_t2,现在需要将表customer_t1中的数据插入到表customer_t2中,则可以执行如下命令。

12345678
openGauss=# CREATE TABLE customer_t2(    c_customer_sk             integer,    c_customer_id             char(5),    c_first_name              char(6),    c_last_name               char(8));openGauss=# INSERT INTO customer_t2 SELECT * FROM customer_t1;

上面的示例等价于:

1
openGauss=# CREATE TABLE customer_t2 AS SELECT * FROM customer_t1;
support.huaweicloud.com/distributed-devg-v2-opengauss/gaussdb-v5r2c10-0052.html