I want to get the latest inserted_at row, in this case - id.112. I actually don’t know how this “function” is called, noob alert
query = from(e in Example, where: e.inserted_at == ???)
Repo.all(query)
For me a where expression should be used, maybe smth kind of where: e.inserted_at > all other rows. The answer is Ecto.Query — Ecto v3.7.1 for sure, but frankly I don’t know what to search for.
order_by is the simplest way if you’re only looking for one record; if you want something more complicated like "give me the most recent row from this table for eachuser_id" you’ll need to look into window functions.
FWIW, the Ecto docs focus mostly on “how to make SQL shaped like X” with Ecto but assume that you know how to translate a requirement like "the latest row by inserted_at" into “I need SQL shaped like X”. If you’re just getting started with both SQL and Ecto, a plain SQL tutorial / reference will help you a lot.
If you are going to do this kind of thing you should also create an index on inserted_at. Otherwise the database will have to scan the entire table and sort it.