-
Preamble
The questionI have an upsert statement along the lines of
Ideally, I'd like to be able to insert multiple rows, but I'm not sure how to idiomatically do that without adding a variable number of placeholders. This is to say, I feel like the string I pass to pgx would have to change based on how many rows I'm upserting:
Is there an idiomatic way to do this in pgx, maybe a test case you could point me at? Meanwhile, in Java landJust for argument's sake, worth noting that
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That's correct. It is rather awkward, but it is necessary to use a variable number of placeholders. (At least unless you did something really crazy like using an array of rows / structs that you used unnest to extract in PostgreSQL -- I don't recommend it 😉 )
Honestly, just use a batch. 😉 It's far simpler and the speed should be comparable, possibly even better as it may make better use of the statement cache. Also, if there is an error it will be much easier to troubleshoot. |
Beta Was this translation helpful? Give feedback.
That's correct. It is rather awkward, but it is necessary to use a variable number of placeholders. (At least unless you did something really crazy like using an array of rows / structs that you used unnest to extract in PostgreSQL -- I don't recommend it 😉 )
Honestly, just use a batch. 😉 It's far simpler and the speed should be comparable,…