In general you can use type/2 to cast between types but this case might be too specialized. For instance type(m.col2, :string) will try to cast col2 by doing m.col2::varchar in postgres. But not sure if that would work for a date type.
In this particular case simple casting won’t work because index needs “IMMUTABLE” function/expression to work with. Or to be more precise, technically it would work but only doing Seq scans. I’ll remember the cast construct out of this though, tnx.
fragment part is clear but to_char() won’t cut it. If you know how to make to_char() “IMMUTABLE” for date columns where there’s no locale stuff involved (like in the ‘YYYY-MM-DD’ format) then I’d gladly drop my custom function
Thank you for the link - I’ll probably stay with raw SQL aka fragment for now. Don’t see it justified to pull-in another dependency or spend time implementing similar approach for a handful of DB functions I need to call on occasions. Basically wanted to be sure that there’s nothing in Ecto that would do the trick w/o falling back to SQL.