Skip to content

Commit

Permalink
fix: ensure GROUP BY comes before limit, offset, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Sep 23, 2022
1 parent 4ccf943 commit 24dc5f8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/postgres/query/base/select.ts
Expand Up @@ -64,6 +64,9 @@ export abstract class SelectBase<From extends Selectable[]> //
return sources
}
protected tokenize(props: SelectProps, ctx: Query.Context) {
if (props.single) {
ctx.single = true
}
const joins = props.joins ? [...props.joins] : []
const selected = [props.from].concat(joins.map(join => join.from))
const tableCasts = findTableCasts(props.from, joins, ctx)
Expand All @@ -82,7 +85,6 @@ export abstract class SelectBase<From extends Selectable[]> //
if (props.where) {
tokens.push(tokenizeWhere(props.where, ctx))
}
tokens.push(tokenizeSetProps(props, ctx))
if (props.groupBy || tableCasts.length) {
tokens.push('GROUP BY')
if (props.groupBy) {
Expand All @@ -96,9 +98,7 @@ export abstract class SelectBase<From extends Selectable[]> //
}
}
}
if (props.single) {
ctx.single = true
}
tokens.push(tokenizeSetProps(props, ctx))
return tokens
}
protected cloneProps() {
Expand Down

0 comments on commit 24dc5f8

Please sign in to comment.