Vertica SQL在一个语句中插入多行

ben*_*890 3 sql vertica

想知道是否有可能在一个插入声明中完成以下内容?

drop table analytics.bw_covariance_matrix;
create table analytics.bw_covariance_matrix (
row int,
x1 float,
x2 float,
x3 float
);

insert into analytics.bw_covariance_matrix VALUES
(1, 4.01926965, -0.4686067, -0.07592112),
insert into analytics.bw_covariance_matrix VALUES
(2, -0.46860675,  4.1799267, -0.82461139);
insert into analytics.bw_covariance_matrix VALUES
(3, -0.07592112, -0.8246114,  4.37186211);
Run Code Online (Sandbox Code Playgroud)

JNe*_*ill 5

您可以UNION使用SELECT来生成单个INSERT语句:

insert into analytics.bw_covariance_matrix 
SELECT 1, 4.01926965, -0.4686067, -0.07592112
UNION
SELECT 2, -0.46860675,  4.1799267, -0.82461139
UNION
SELECT 3, -0.07592112, -0.8246114,  4.37186211
Run Code Online (Sandbox Code Playgroud)

我不相信Vertica有像MySQL和其他RDBMS这样的多记录插入语句,所以这是最好的选择.

  • 并不是因为这个行数很重要,但是UNION ALL会更快,因为你可以控制行并且不需要区分. (2认同)