Search code examples
elixirecto

Elixir + Ecto: Simple WHERE != query


How do you do WHERE != "something" in Ecto? I'm using postgres

This is what I have (that doesn't work):

u = User |> Ecto.Query.where(id: not 444) |> MyApp.Repo.one


Solution

  • You'll need to use the Ecto Query macros to build this query. For the "expression" based syntax, you can pass a list as the first parameter with the names you'd like to bind the tables with:

    User |> where([u], u.id != 444)
    

    For more info, check out the documentation of where.