Fast Bulk queries for postgres and MSSQL using JS ->JSON->SQL

Welcome to the forum @Kat . Love that your first post is to pass on some knowledge!

I usually make a Stored Procedure on the back end when I need to do complicated things or need to use transactions, I guess I can just put it directly into a SQL query and not bother the server with storing it? Also good for those that do not have permissions to add a stored procedure. I'll have to play with that. But will need some testing to see if it really does what I need (like will it really allow transactions?) Thank you for opening that mental door.

Back to the subject: I think I have an even easier way to accomplish what it looks like you are doing and that is with Bulk Update or Bulk Insert queries. (Write data to SQL databases)

Here is an example: How do I add multiple rows to table in PostgreSQL? - #2 by bradlymathews

Let's say we take your mapped array values (an object of arrays) you first need to change it to an array of objects, put this in Array of records to update: formatDataAsArray(myArray). Teh function formatDataAsArray() is built in and that does what your JS code in Step 2 does.

When using the bulk query, Retool will convert the data into a single query with multiple inserts or updates and pass that to your database. It also know the difference between MySQL, SQL Server, Postgres, etc., so you don't have to worry about it.

2 Likes