Question: Multi-insert statement
See original GitHub issuePostgres supports something like:
INSERT INTO foo(a,b) VALUES (q,r), (s,t) ...
How can I do this in node-postgres
? Right now I’m using a transaction, and async.parallelLimit
for individual INSERT
s. But this seems rather inefficient, and it’s as I need it for a reasonably high-volume log – where every few seconds I need to insert quite a bit of data – performance matters.
So I’m wondering if there’s a better way. (And I happy to string concat my own query, but I don’t an escaping function exposed)
Issue Analytics
- State:
- Created 10 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Inserting multiple rows in a single SQL query? - Stack Overflow
In SQL Server 2008 you can insert multiple rows using a single SQL INSERT statement. INSERT INTO MyTable ( Column1, Column2 ) VALUES ......
Read more >SQL Query to Insert Multiple Rows - GeeksforGeeks
In this article, we see how to insert individual as well as multiple rows in a database using the INSERT statement in the...
Read more >How to INSERT Multiple Records in SQL - DigitalOcean
The SQL UNION query helps to select all the data that has been enclosed by the SELECT query through the INSERT statement.
Read more >How to Insert Multiple Rows in SQL - Database Star
This works in all database vendors. INSERT INTO customer (first_name, last_name) SELECT fname, lname FROM list_of_customers WHERE active = 1;
Read more >How to Insert Multiple Rows in a Single SQL Query
Answer: Writing a code to insert multiple rows in a single SQL query is not a difficult task, but it is indeed a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The above needs a slight tweak in the middle to actually work:
FYI for anyone reading the thread,
buildStatement
returns the following SQL:You can still do this with a prepared statement, you’ll just have to build up the parameters and append them all to the query…something like:
Something like that. I wrote it off the top of my head. There are also a myriad of query builders for node which should help make this much easier.