Ecto and Enum.uniq_by

Hi Folks.

I’m struggling to get an Ecto query to work with order_by and distinct. Basically if I add the distinct option then the order_by doesn’t work.

My current solution is to remove the distinct option and pass the result through an Enum.uniq_by which does work. I’m just curious if this is something I should be doing. I know I should let the database do all the work and this might be a performance hit but I’m only talking about a couple of 100 records at max.

any thoughts?



Then it probably won’t matter as long as the input table is not too large or it is initially collecting it via a map or indexed lookup. :slight_smile:

You can use MapSet.

|> Repo.all()
|> Enum.into(

This will return you only unique values.