If there is a way to do this within a query then you still might be going against the grain.
The way I see it, SQL’s GROUP BY wants to aggregate records in a merging kind of way, i.e., returning a smaller number of records than without the GROUP BY.
However, the above map wants all the records, but just lumped in a certain way.
In this situation, I think we’re dealing with two different meanings of the term “group by”; SQL’s meaning and Elixir’s meaning, e.g., Enum.group_by/3.
As @evadne suggested, perhaps first retrieve the Post structs and then group them.
If this two-step approach is cause for concern then by all means share it; there might be a better way.