apr

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

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

5, they are not batched.

Also Liked

dimitarvp

dimitarvp

  • You can use Multi.run with 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_all and update_all.

Last Post!

tme_317

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.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement