如何编写此Ecto查询?

时间:2018-11-17 08:07:51

标签: erlang elixir ecto

我正在尝试这样做:

UPDATE subscribers
SET last_pushed_at = now()
FROM (
  SELECT id
  FROM subscribers
  ORDER BY last_pushed_at ASC NULLS FIRST
  LIMIT 5
) oldest
WHERE oldest.id = subscribers.id
RETURNING subscribers.username

这是我到目前为止所拥有的...可悲的是:

sq = from(s in Ztz.Subscriber,
  select: {s.id},
  order_by: [:asc_nulls_first],
  limit: ^demand
)  

subscribers = Repo.update_all(
  from(oldest in subquery(sq),
    set: [last_pushed_at: DateTime.utc_now()],
    where: oldest.id == s2.id,
  )
)

0 个答案:

没有答案