ROLLBACK - Unable to perform operation using terminated connection

Thank you for coming to office hours, Kirk! Posting our conversation so we can continue it here:

My teammate wrote this JS snippet (to use in a JS Query) up for another user running into the same issue trying to run a bulk insert statement with an array column in Snowflake:

const jsonData = mergeAPI.data

let values = "";

jsonData.forEach(row => {

  let rowValues = "";

  Object.keys(row).forEach(key => {
    let value = row[key];

    if (typeof value === 'number') {
      value = value; // no quotes 
    } else if (typeof value === 'string') {
      value = `'${value}'`; // single quotes
    } else if (value instanceof Date) {
      value = value.toISOString().slice(0,10); // date format
    } else {
      value = JSON.stringify(value); // other types
    }

    rowValues += value + ",";

  });

  rowValues = rowValues.slice(0,-1); // remove trailing comma

  values += `(${rowValues}),\n`;

});

values = values.slice(0, -2); 

const columns = Object.keys(jsonData[0]).join(",");

const query = `INSERT INTO merge.balance_sheets (${columns}) VALUES ${values}`;


return query

where merge.balance_sheets is the table name

1 Like