Issues Inserting Multiple Rows Using Array of Objects in SQL with ReTool

Hi everyone,

I'm working with ReTool and am trying to insert multiple rows of data into a SQL table using an array of objects in a workflow code block. While I can perform this operation successfully through the GUI, I'm encountering issues when trying to execute the same operation via a SQL statement.

const fetchedArticles = fetchArticles.data.articles.results;

const articlesContent = fetchedArticles.map(article => ({
  title: article.title
}));

console.log(articlesContent);

return articlesContent;

INSERT INTO articles (title) VALUES {{ fetchContent.data }}

I have also attempted to convert the array of objects into a joined string format for the SQL statement.

Am I on the right track, or should I shift my methods? Thanks for any guidance in advance.

Hi @matt.em,

If you switch over to GUI mode for your query and set it to bulk insert, you should able to accomplish what you're looking for.

image

This will create an array of objects with just a title property and will insert them all into your specified table.

It can be very tricky to format a bulk insert in SQL mode, so I definitely recommend trying to work with the GUI mode if possible!