Is there a possibility to use https://hexdocs.pm/ecto/Ecto.Query.API.html#merge/2 to first transform the struct on the left hand side to a map, so that new keys can be added?
from(city in City, select: merge(city, %{new_field: "some_value"}))
so the return value would be a map instead of a struct.
Something like this, if map/1
would exist that would just return the full map
from(city in City, select: merge(map(city), %{new_field: "some_value"}))
My use case is the following. I want to find all duplicates and mark them.
I’m taking inspiration from the query from: https://blog.theodo.com/2018/01/search-destroy-duplicate-rows-postgresql/
SELECT * FROM
(SELECT *, count(*)
OVER
(PARTITION BY
firstname,
lastname
) AS count
FROM people) tableWithCount
WHERE tableWithCount.count > 1;
and want to do this with subquery and for that I need to return a map.