ycv005
Ecto query into Plain SQL
How to convert following Ecto Query into the Plain RAW SQL
%Workspace{name: "#{prefix() || "public"}"} |> Repo.insert()
Your response will be highly appreicable.
Most Liked
mxgrn
Wow, I just found GitHub - akoutmos/ecto_dbg: A utility to format and output Ecto queries
It produces well-formatted, copy-paste-ready SQL right into my logs ![]()
![]()
@akoutmos
LostKobrakai
Did you try it?
It’s documented here: https://github.com/elixir-ecto/ecto_sql/blob/2ec71d74655cc076b6c965740a357dfe1505883a/lib/ecto/adapters/sql.ex#L228-L232 and here’s the macro, which adds it to the repo: https://github.com/elixir-ecto/ecto_sql/blob/2ec71d74655cc076b6c965740a357dfe1505883a/lib/ecto/adapters/sql.ex#L374-L427
It’s not part of the Ecto.Repo behaviour though, which is why it’s not documented in that module. It’s only available if you’re using a SQL based adapter.
LostKobrakai
I don’t know what exactly happens behind the scenes, but I doubt the db does actually interpolate values:
Repo.explain(:all, query)
https://hexdocs.pm/ecto_sql/3.11.3/Ecto.Adapters.SQL.html#explain/3
hauleth
What are you trying to do exactly. Because I have strange feeling that we are dealing with XY problem.








