Ecto query into Plain SQL

It looks like you want to convert an ecto query to an sql query to use in migrations (hence the execute). The problem here is that ecto actually cannot do that completely. Ecto as well as the underlying postgrex adapter does never interpolate parameters into the query. This is left to the database to do. So you’ll at best get the query with placeholders in the sql query and you’re left to replace those with actual values on your own. That’s why to_sql returns a tuple of {query, parameters}.