Search code examples
elixirecto

notBetween ecto query


I have a query which return the results between the values we passed into it in the params if we passed [value1, value2] like this:

  where: field(name) > ^Enum.min(value 1)
  and field(name) < ^Enum.max(value 2)

Its returning the records between value1 and value 2.

I want to implement notbetween. which will return records less than value1 and greater than value 2

Any suggestions?

Thanks


Solution

  • will return records less than value1 and greater than value 2

    Just reverse the condition (note or to return either those less, or those greater):

    where: field(name) < ^Enum.min(value 1)
        or field(name) > ^Enum.max(value 2)