I have the following insert
insert into countries values select 'ru', 'Russia' where not exists ( select * from countries where iso_code = 'ru' )
I can use fragments for this but then listing columns of the
Country schema will have to be manual. Is there a simple way to generate that sort of query with changesets?
So basically you want to insert into database the row if it does not exist just yet. What I would do is have unique index on iso_code column and then have upsert with Ecto that does nothin (or updates all).
this is a contrived example. I can not have the unique index you mentioned.