title: Executing Insert Statements in Parallel in Snowflake
body: <p>I have a stored procedure that executes 3 <a href="https://www.w3schools.com/sql/sql_insert_into_select.asp" rel="nofollow noreferrer">insert/select</a> statements into 3 different tables in Snowflake: ScheduleUnion, ScheduleUnion1, ScheduleUnion2. Now due to the time each statement takes to complete, i'd like to execute them in parallel to cut down on the overall execution time.To do this, I'm trying to make use of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all" rel="nofollow noreferrer">Promise.all</a> in Javascript. I'm not going to post all of the insert statements here, but this sample is a good representation of how I'm tying to do this:</p>
  <pre><code>CREATE OR REPLACE procedure etl.&quot;JimTest&quot; ()
  RETURNS VARCHAR
  LANGUAGE JAVASCRIPT 
  AS
  $$
  
     async function runSQL(sqlarray) {
  
     snowflake.execute({ sqlText: sqlarray.sqltask } );
    }
  
     async function executeQuery() {
  
      sql1 = `INSERT into ScheduleUnion Select.....`
      sql2 = `INSERT into ScheduleUnion1 Select.....`
      sql3 = `INSERT into ScheduleUnion2 Select.....`
  
       const queries = [
          {sqltask: sql1},
          {sqltask: sql2},
          {sqltask: sql3}
      ];
  
      const sqlTasks = queries.map(runSQL);
  
      await Promise.all(sqlTasks); 
   }
  
    executeQuery();
  
    return 'done';
  $$
  </code></pre>
  <p>However; I still see my insert statements running serially, one after the other:</p>
  <p><a href="https://i.stack.imgur.com/neAda.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/neAda.png" alt="enter image description here" /></a></p>
  <p>Is there a <a href="https://docs.snowflake.com/en/sql-reference/parameters.html" rel="nofollow noreferrer">parameter</a> I'm missing, or something wrong with my Javascript?</p>