Elixir 如何在EXTO中搜索数组长度

Elixir 如何在EXTO中搜索数组长度,elixir,ecto,Elixir,Ecto,假设我有一个模式 defmodule User do use MyApp.Web, :model schema "users" do field :loved_numbers, {:array, :integer} end end 我如何使用exto.Query搜索恰好有2个爱过的号码的所有用户 此查询在PostgreSQL和MySQL中都能工作吗?对于PostgreSQL,您可以使用片段使用array\u length函数: from(u in User, where

假设我有一个模式

defmodule User do
  use MyApp.Web, :model

  schema "users" do
    field :loved_numbers, {:array, :integer} 
  end
end
我如何使用
exto.Query
搜索恰好有2个
爱过的号码的所有用户


此查询在PostgreSQL和MySQL中都能工作吗?

对于PostgreSQL,您可以使用片段使用
array\u length
函数:

from(u in User, where: fragment("array_length(?, 1)", u.loved_numbers) == 2)
(对于要计数的维度,
1
,对于一维数组,它应该是
1
。)


据我所知,.

我想您将不得不使用片段,而它在PostgreSQL和MySQL中都不起作用。