question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Multi-row insert support

See original GitHub issue

Would you be interested in building support for multi row insert into the parameterization semantics?

The mysql package as something like this:

query('INSERT INTO foo (f1, f2, f3) VALUES ?', [[1,2,3], [4,5,6], [7,8,9]])

Which results in a query like:

INSERT INTO foo (f1, f2, f3) VALUES (1,2,3), (4,5,6), (7,8,9);

Would you be interested in adding this feature to pg? If so I can take a look at what it would take. Probably it cannot be the same api, but some version would be nice IMO.

Other related issues: #530 #1644

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
madacolcommented, Mar 7, 2021

Another option https://stackoverflow.com/a/37445088/3163120

const obj = [
   {operation:"U",taxCode:1000},
   {operation:"U",taxCode:10001}
]
query(`
      INSERT INTO table (operation, taxCode)
      SELECT *
      FROM json_to_recordset($1)
      AS x("operation" text, "taxCode" int);
   `,
   [JSON.stringify(obj)]
)

Result

------------------------
| id|operation|taxCode |
------------------------
| 1 |   "U"   |   1000 |
------------------------
| 2 |   "U"   |  10001 |
------------------------
Read more comments on GitHub >

github_iconTop Results From Across the Web

NET Multi-Row SQL insert support for set based operation
If we want to insert multiple values into a table in SQL, we could use the following method: INSERT INTO MyTable VALUES (1,'a','foo'); ......
Read more >
How to INSERT Multiple Records in SQL
Traditional SQL INSERT query injects input data into multiple rows. In this technique, we need to the insert query as many times we...
Read more >
Multi-row insert - Forums - IBM Support
Hi,. Does anyone have a multi-row insert example on C#.Net. My host server is db2 V8 and i am using FW 2 in...
Read more >
Use a multi-row insert - Amazon Redshift
Multi-row inserts improve performance by batching up a series of inserts. The following example inserts three rows into a four-column table using a...
Read more >
Why does Oracle still not support Multi-Row insert? [closed]
According to Wikipedia's article about INSERT in SQL, multi-row inserts are standard since SQL-92. Oracle (up to 11g at least) does not support...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found