title: Raw sql with many columns
body: <p>I'm building a CRUD application that pulls data using Persistent and executes a number of fairly complicated queries, for instance using window functions. Since these aren't supported by either Persistent or Esqueleto, I need to use raw sql.</p>
  
  <p>A good example is that I want to select rows in which the value does not deviate strongly from the previous value, so in pseudo-sql the condition is <code>WHERE val - lag(val) &lt;= x</code>. I need to run this selection in SQL, rather than pulling all data and then filtering in Haskell, because otherwise I'd have way to much data to handle.</p>
  
  <p>These queries return many columns. However, the <code>RawSql</code> instance maxes out at tuples with 8 elements. So now I am writing additional functions <code>from9, to9, from10, to10</code> and so on. And after that, all these are converted using functions with type <code>(Single a, Single b, ...) -&gt; DesiredType</code>. Even though this could be shortened using code generation, the approach is simply hacky and clearly doesn't feel like good Haskell. This concerns me because I think most of my queries will require <code>rawSql</code>.</p>
  
  <p>Do you have suggestions on how to improve this? Currently, my main thought is to un-normalize the database and duplicate data, e.g. by including the lagged value as column, so that I can query the data with Esqueleto.</p>