I’m attempting to replicate an INSERT … SELECT in Ecto. This appears to be supported by both postgres and mysql (I’m using postgres). I’ve got this working in SQL, but trying to recreate in Ecto.Query.
I created an ecto query that returns the data I want, and tried passing it to insert or insert_all and both seemed to cause errors.
Is there a supported method to do this, or is the official answer, “just use sql”?
insert_all does support using a query, similar to what you’ve suggested, but only to return a single value. It doesn’t appear to build/use the INSERT INTO … SELECT statement.
The keys of the entries are the field names as atoms and the value should be the respective value for the field type or, optionally, an Ecto.Query that returns a single entry with a single value.
Found the PR that implemented the suporte for single return subquery on insert_all.
Maybe I will have a look this weekend to see if its easy to implement this.