Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertica SQL insert multiple rows in one statement

Tags:

sql

vertica

Was wondering whether it's possible to accomplish the following in one insert statement?

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);
like image 216
ben890 Avatar asked Aug 27 '26 03:08

ben890


1 Answers

You could UNION a SELECT to have a single INSERT statement:

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

I don't believe that Vertica has a multi record insert statement like MySQL and other RDBMS's, so this is the best bet.

like image 148
JNevill Avatar answered Aug 29 '26 19:08

JNevill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!