slick-pg icon indicating copy to clipboard operation
slick-pg copied to clipboard

aggregate results of windowing functions

Open evbo opened this issue 6 years ago • 1 comments

I need to take the min of the max in each group, e.g.:

import com.github.tminglei.slickpg.ExPostgresProfile.api._
import com.github.tminglei.slickpg.agg.PgAggFuncSupport.GeneralAggFunctions._

...

Table.map{ q =>
        (
          max(q.col).over.partitionBy(q.id).sortBy(q.col),
          q.id
        )
      }
.groupBy{_ => true}
      .map {
        case (_, query) =>
          query.map(_._1).min
      }

bit it attempts to compose the window function inside the aggregate, which is not allowed and yields:

The future returned an exception of type: org.postgresql.util.PSQLException, with message: ERROR: aggregate function calls cannot contain window function calls

Can it be supported such that it does a subquery instead?

evbo avatar Aug 21 '19 19:08 evbo

@evbo not easy, didn't find a good way out yet. :-(

tminglei avatar Aug 22 '19 09:08 tminglei