apr
Are transactions batched?
Hello,
I realize this is a DB question, but it involves Ecto and Postgrex so I thought I’d post here.
Suppose I have a multi with many inserts/updates using both Multi.run and Multi.insert/update. I commit the changes to this multi using Repo.transaction() (on a PostgreSQL DB using the Postgrex driver.)
I have a couple of questions. First, are the insert/updates batched? As in, if I have three inserts and two updates, will there be one round trip to the remote DB server or five round trips? Second, if indeed these statements are batched, how is it possible to get the updated DB state inside the multi before the multi is committed?
Thanks!
Marked As Solved
benwilson512
Also Liked
dimitarvp
- You can use
Multi.runwith your function passed as a parameter and you get the state so far in its parameters (Ecto calls it during the transaction, at the time of your choosing. Check the docs.). - Not sure your original problem has any other answers except for using
insert_allandupdate_all.
Last Post!
tme_317
It may be possible to send the data to the DB to temporary “staging” table(s) using insert_all or copy from csv or stdin then issuing inserts/updates/upserts atomically in a transaction once it is uploaded. Depends on what you are doing but this could be faster than creating a massive list of operations inside a Multi.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









