Concatenate String inside a Select in Query

Hi, I’m trying to concatenate two variables in the select field inside a query. Is this possible?

Repo.one(from a in Apple, where: a.id == 1, select: %{name: a.name <> a.color})

I’ve tried Enum.join, and the error seems to be the same

1 Like

The concatenation in a select expression needs to be understood by Ecto and your target database. In this case, the Elixir string concatenation operator is not interpreted by Ecto (ie not translated into the required underlying SQL). This link may help (tldr; use a fragment with the SQL concat function): https://stackoverflow.com/questions/43593212/elixir-ecto-postgres-select-multiple-columns-as-one

1 Like

Thanks! That was the answer