Sure
This:
from(i in Invoice,
where: i.synced == false and
(is_nil(i.sync_started_at) or i.sync_started_at < ^min_sync_started_at),
order_by: i.inserted_at,
limit: ^batch_size
)
|> Repo.update_all(
set: [sync_started_at: Ecto.DateTime.utc()],
returning: true
)
Gives:
** (ArgumentError) malformed update `[set: [sync_started_at: #Ecto.DateTime<2017-06-26 13:27:22>], returning: true]` in query expression, expected a keyword list with lists or interpolated expressions as values
(ecto) lib/ecto/query/builder/update.ex:170: Ecto.Query.Builder.Update.runtime_error!/1
(elixir) lib/enum.ex:1247: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(elixir) lib/enum.ex:1247: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(ecto) lib/ecto/query/builder/update.ex:136: Ecto.Query.Builder.Update.update!/4
(ecto) lib/ecto/repo/queryable.ex:88: Ecto.Repo.Queryable.update_all/5
Similar one, without "returning":
from(i in Invoice,
where: i.synced == false and
(is_nil(i.sync_started_at) or i.sync_started_at < ^min_sync_started_at),
order_by: i.inserted_at,
limit: ^batch_size
)
|> Repo.update_all(
set: [sync_started_at: Ecto.DateTime.utc()]
)
Results in:
** (Ecto.QueryError) `update_all` allows only `where` and `join` expressions in query:
from i in MyApp.Models.Invoice,
where: i.synced == false and (is_nil(i.sync_started_at) or i.sync_started_at < ^#Ecto.DateTime<2017-06-26 13:30:43>),
order_by: [asc: i.inserted_at],
limit: ^10,
update: [set: [sync_started_at: ^#Ecto.DateTime<2017-06-26 13:31:44>]]
(ecto) lib/ecto/repo/queryable.ex:122: Ecto.Repo.Queryable.execute/5
Also:
subset_query = from(i in Invoice,
where: i.synced == false and
(is_nil(i.sync_started_at) or i.sync_started_at < ^min_sync_started_at),
order_by: i.inserted_at,
limit: ^batch_size
)
from(i in subquery(subset_query))
|> Repo.update_all(
set: [sync_started_at: Ecto.DateTime.utc()]
)
Gives:
** (Ecto.QueryError) `update_all` does not allow subqueries in `from` in query:
from i in subquery(from i in MyApp.Models.Invoice,
where: i.synced == false and (is_nil(i.sync_started_at) or i.sync_started_at < ^#Ecto.DateTime<2017-06-26 13:40:30>),
order_by: [asc: i.inserted_at],
limit: ^10,
select: i),
update: [set: [sync_started_at: ^...]]
(elixir) lib/enum.ex:1623: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto) lib/ecto/repo/queryable.ex:122: Ecto.Repo.Queryable.execute/5
I think that's about it with what we've tried, maybe minor variations along the way with the same results.
Hope it helps!
Vanja