theshank
My use case is perfectly served by the update ... from syntax for Postgres as per the query below:
update test as t set
column_a = c.column_a,
column_c = c.column_c
from (values
('123', 1, '---'),
('345', 2, '+++')
) as c(column_b, column_a, column_c)
where c.column_b = t.column_b;
This is taken from this question on Stackoverflow.
Is there any way to achieve this using ecto?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
OvermindDL1
I’m pretty sure
Repo.update_alldoes that? I think?theshank
I believe the “values” that will be there in the updated records when using
update_allwill be the same for all the updated records.In my use case, I have a list of
ids and the new value for a particular field for each of thoseids. The next values are different for each id. Something like below:update_allwont work for this case… right?OvermindDL1
Good question, if it does not have a way to accept a list of updates, it should. ^.^;
theshank
Thanks.. will go with the raw sql query then.
gregvaughn
hehe, yeah, I just did this in raw sql (via
Ecto.Adapters.SQL.query!) about an hour agotheshank
Can you tell me how to convert (cast?) an elixir DateTime (say the value I get from of
DateTime.utc_now()), into a Postgres column of typetimestamp without time zone.LostKobrakai
Ecto.Type.dump/2 might do that.
theshank
Thats great! I am new to the whole Elixir ecosystem and Ecto. Thank you for pointing me in the right direction.
Just to confirm, i can use the value obtained from
Ecto.Type.dump(:utc_datetime, DateTime.utc_now())in my raw sql query. Does my understanding appear correct?voger
Why? SQL has it’s own functions for datetime if you want to go that route.
I am a noob too when it comes to SQL.
Here are PostgreSQL date functions if you use PostgreSQL. PostgreSQL: Documentation: 9.6: Date/Time Functions and Operators
Also I am not sure what exactly does your query do in your first post. As I said I am a noob also. But I had a situation recently where I had to update multiple records with different values. I ended reading those records from the database (
Repo.all(query...)) then iterating over them and appending in a Multi and finally applying everything in a transaction. A total of 2 database transactions. No need for raw SQL.I don’t know if it is proper or if there are better ways. Just throwing an idea.
theshank
Thanks for both the suggestions!
Using Ecto.Multi might also be a good option… My use-case is to update a few thousand records every minute with new values. These records are just recurring “jobs” that have a “scheduled_time”. Every minute, the jobs that have completed in the past minute are updated with the new values for the “scheduled_time” for the next run.