tusken icon indicating copy to clipboard operation
tusken copied to clipboard

Warn when aggregate function is used alongside non-aggregate selection

Open aleclarson opened this issue 3 years ago • 1 comments

If an aggregate function is used within a db.select call, you need GROUP BY to include non-aggregate selections.

Current progress

  • [x] Generated defineFunction calls use the Aggregate type instead of Output in their type signatures
  • [ ] TypeScript emits an error when a selection includes both Aggregate and non-aggregate types

aleclarson avatar Sep 02 '22 20:09 aleclarson

We'll probably add a groupBy helper function for use in the selector function.

db.select(t.user(user => [
  groupBy(user.id),
  pg.avg(user.followerCount),
]))

aleclarson avatar Sep 20 '22 15:09 aleclarson