Pivot queries in Ecto

So I’m trying to pivot a query result in ecto, however it seems that what I’d think the obvious way to do it is not working…

from ct in fragment("crosstab2(?)", subquery(squery))

It will not compile, saying that fragment is an undefined function. What is the proper way to do this? Basically instead of crosstab2 I’d prefer to use crosstab (due to things I want done in specific ways), but I cannot seem to name the setof in Ecto either. Basically I’m wanting to make this query:

SELECT crossed.* FROM crosstab('SELECT blah other stuff') AS crossed(pidm integer, name text, date date)

But I cannot seem to do it, how do you do this in Ecto? How do you do pivot queries in ecto at all really?

1 Like