I wanted to convert at least the nested part SELECT tsv FROM products WHERE ... to an Ecto subquery.
So I don’t have to write the WHERE clause as raw SQL.
But also with_cte I do not get it working.
I think with with_cte I also need to use fragment for ts_stat(?).
And it seems that fragment of course does not expect a subquery.
Ah, didn’t notice that. Yeah, a function receiving a query as text is not really something ecto can handle. You can use Repo.to_sql to generate the sql from an ecto query, but that won’t interpolate params, so it’s rather half of a solution.
Thanks Benjamin.
Currently I’m blind in seeing a solution in it, but I’m not in top form today.
Maybe I revisit later or maybe it needs to stay raw SQL.