INSERT_ ALL
Warning
SingleStore 9.0 gives you the opportunity to preview, evaluate, and provide feedback on new and upcoming features prior to their general availability. In the interim, SingleStore 8.9 is recommended for production workloads, which can later be upgraded to SingleStore 9.0.
On this page
Inserts an array of records into a table in a single operation.
Provides much better performance than doing singleton inserts in a LOOP.
Syntax
INSERT_ALL("table_name", array);
Arguments
-
table_
: the name of the table to insert the values intoname -
array
: the array of values
Remarks
-
The current database is used when calling
INSERT_
, so any tables specified inALL table_
must reside in that database.name Qualified table names, such as database.
, will be treated as unqualified table names.table
Example
The stored procedure, t2Slow, performs singleton inserts into table t2, while t2Fast inserts the same values using the INSERT_
function.
CREATE TABLE t2 (a INT, b INT);DELIMITER //CREATE OR REPLACE PROCEDURE t2Slow(count INT) ASBEGINFOR i IN 1..count LOOPINSERT INTO t2 VALUES (i, i);END LOOP;END //CREATE OR REPLACE PROCEDURE t2Fast(count INT) ASDECLAREarr ARRAY(RECORD(a INT, b INT)) = CREATE_ARRAY(count);x INT;BEGINFOR i IN 0..(count-1) LOOParr[i] = ROW(i+1, i+1);END LOOP;x = INSERT_ALL("t2", arr);end //DELIMITER ;-- Insert 1,000,000 rows into t2 using both stored procedures. Note: These query times are based on a cluster hosted on a single machine.CALL t2Slow(1000000);Query OK, 0 rows affected (3 min 31.12 sec)CALL t2Fast(1000000);Query OK, 0 rows affected (33.13 sec)
Last modified: November 17, 2022