gpt4 book ai didi

elixir - 如何使用 Ecto 构建 WHERE IN 数组子句?

转载 作者:行者123 更新时间:2023-12-03 09:14:25 24 4
gpt4 key购买 nike

如何在给定的 ID 列表中查找帖子?

这不起作用:

posts = Post |> where(id: [1, 2]) |> Repo.all

Rails 中的示例:
Post.where({ id: [1, 2]})
# SELECT * FROM posts WHERE id IN (1, 2)

最佳答案

以下应该工作:

posts = Post |> where([p], p.id in [1, 2]) |> Repo.all

关于elixir - 如何使用 Ecto 构建 WHERE IN 数组子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36814260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com