INSERT_ALL

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_name: the name of the table to insert the values into

  • array: the array of values

Remarks

  • The current database is used when calling INSERT_ALL, so any tables specified in table_name must reside in that database. Qualified table names, such as database.table, will be treated as unqualified table names.

Example

The stored procedure, t2Slow, performs singleton inserts into table t2, while t2Fast inserts the same values using the INSERT_ALL function.

CREATE TABLE t2 (a INT, b INT);
DELIMITER //
CREATE OR REPLACE PROCEDURE t2Slow(count INT) AS
BEGIN
FOR i IN 1..count LOOP
INSERT INTO t2 VALUES (i, i);
END LOOP;
END //
CREATE OR REPLACE PROCEDURE t2Fast(count INT) AS
DECLARE
arr ARRAY(RECORD(a INT, b INT)) = CREATE_ARRAY(count);
x INT;
BEGIN
FOR i IN 0..(count-1) LOOP
arr[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

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK