Pivot queries using Ecto

I’m trying to unpivot the result of a query built with Ecto using a postgres backend. Any tips on how to do that? If it’s not a built-in functionality, I’m of course happy to use a fragment. I’ve played around a bit but didn’t get anything to compile.

An internet search didn’t reveal much: I only found this old question that didn’t get any responses.