1
votes

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

1
|> where([u], u.id != 444)? - Dogbert
please give me all your elixir knowledge @Dogbert - bigpotato
There's a reference of the various boolean operators here: elixir-lang.org/getting-started/basic-operators.html. I'm not sure why you didn't try != first yourself. - Onorio Catenacci

1 Answers

5
votes

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.