SELECT atom literal in ecto

I want to get a tuple from ecto, with a literal atom.. bit I cannot figure out if that is possible or not.

This works:

Ecto.Query.from(u in User, select: {u.id, u.username})

And I get a list of tuples back.

Conceptually I want to do this

Ecto.Query.from(u in User, select: {:user, u.id, u.username})

And get tuples like {:user, 32782, “kwando”} back.

So I guess my question is if that it possible and what the syntax is if it possible?

I’m not doing much of ecto, but if that doesn’t work out of the box, I’d try ^:user or a pre-assigned variable and pin that.

Yep, I tried to with pin.. did not work :slight_smile:

AFAIK you can’t select atoms.

The “best” you can do is select strings and then map them through String.to_atom

Ecto.Query.from(u in User, select: {"user", u.id, u.username}) 
|> Repo.all() 
|> Enum.map(fn {a, b, c} -> {String.to_atom(a), b, c} end)