You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I end up getting the following cannot insert multiple commands into a prepared statement.
Why is it like this? What are the reasons?
I think it would be really useful to be able to run multiple commands in the same prepared statement, in order to be able to run a single query with many ( N) commands, instead of N different queries with 1 single command.
I'd like to open up a discussion about this, if it has not been discussed before.
@honestserpent PostgreSQL itself doesn't support this operation. Use a flow control library, async/await, etc & send each query one after another. Or if you don't care about transactions you can use await Promise.all([pool.query('one'), pool.query('two')]) and do two queries at once. Generally though the best thing to do is just send them one at a time - that's how PostgreSQL was designed to work on a protocol level and it ends up being the easiest to reason about errors in your application this way as well I've found. 😄
@abenhamdine I'll try to get to that doc as soon as I can! It definitely does seem like a question that comes up frequently.
Reacted by Angel C., Barney, Will Keleher and Victor Ajibade
Activity
abenhamdine commentedon Aug 4, 2017
see #1388 and related threads for more explanation
officer-rosmarino commentedon Aug 4, 2017
@abenhamdine thanks!
brianc commentedon Aug 4, 2017
@honestserpent PostgreSQL itself doesn't support this operation. Use a flow control library, async/await, etc & send each query one after another. Or if you don't care about transactions you can use
await Promise.all([pool.query('one'), pool.query('two')])and do two queries at once. Generally though the best thing to do is just send them one at a time - that's how PostgreSQL was designed to work on a protocol level and it ends up being the easiest to reason about errors in your application this way as well I've found. 😄@abenhamdine I'll try to get to that doc as soon as I can! It definitely does seem like a question that comes up frequently.