【问题标题】:Phoenix/Ecto - query for match in array of objectsPhoenix/Ecto - 查询对象数组中的匹配项
【发布时间】:2021-12-26 15:18:20
【问题描述】:

(Ecto.Query.CompileError) any(l.signers) 不是有效的查询表达式。

(from l in Listing, where: "xxxxxx@gmail.com" == any(l.signers))
    |> Repo.all()

【问题讨论】:

  • 你的问题是什么,顺便说一句?

标签: postgresql elixir ecto phoenix


【解决方案1】:

从 'xxxxxx@gmail.com' = ANY(signers) 的列表中选择 ID、地址、所有者;

此查询在 PostgreSQL 中有效。

【讨论】:

    【解决方案2】:

    Ecto.Query.API.in/2 应该用来覆盖 ANY 选择器。

    where: ^mail_addr in l.signers
    

    假设l.signers是一个可枚举的。

    【讨论】:

    • 我得到这个错误值"xxxxxx@gmail.com" in where cannot be cast to type {:array, :string} in query:
    猜你喜欢
    • 1970-01-01
    • 2018-05-23
    • 1970-01-01
    • 2021-07-08
    • 2018-09-24
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多