Repo.stream with updates

157 views
Skip to first unread message

Ivan Yurov

unread,
Apr 2, 2022, 12:55:57 AM4/2/22
to elixir-ecto
Is there a fundamental reason why queries with updates cannot be ran with Repo.stream? I get this error, when trying to stream a query built with Query API: (Ecto.QueryError) `all` does not allow `update` expressions in query:` meanwhile supplying a plain SQL version of the same query to Ecto.Adapters.SQL.stream seems to work. I see it's happening during query normalization and I suspect that invariant check there is a bit too restrictive.

Greg Rychlewski

unread,
Apr 10, 2022, 9:40:33 PM4/10/22
to elixir-ecto
When Repo.Stream prepares the query statement for the cache, it has to know the operation: `all` (select), `update_all`, `delete_all` or `insert_all`. The stream function sets the operation as `all`, probably because selecting large result sets is its main usage.

Removing the restriction in the normalization would allow you to generate the query statement but  it would be created as a select instead of an update. You can maybe detect `all` vs `update_all` by looking at the `updates` key on the query struct before sending it to the planner, but I haven't investigated it too thoroughly.

Reply all
Reply to author
Forward
0 new messages