I have an Ecto.Query
and a Repo
, such that I can call Repo.all(query)
and get results. However, the results are not what I expect.
How can I see the raw SQL the Repo
will generate from the Ecto.Query
?
I have an Ecto.Query
and a Repo
, such that I can call Repo.all(query)
and get results. However, the results are not what I expect.
How can I see the raw SQL the Repo
will generate from the Ecto.Query
?
A convenient helper method for printing raw SQL
You can use Ecto.Adapters.SQL.to_sql/3:
The query can be any struct that implements the Ecto.Queryable protocol like
Post
above(which is a module that importsEcto.Schema
). AnEcto.Query
can also be passed:It's basically
Gazler
s answer, but modified to use in code:You could use simple
IO.inspect
, but it'll output a query with backslashes.