Skip to content

Commit

Permalink
fix: allow Limit() without Order() with MSSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
CL-Jeremy committed Jul 16, 2024
1 parent 1573ae7 commit d566c86
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ func (q *SelectQuery) appendQuery(
if count && !cteCount {
b = append(b, "count(*)"...)
} else {
// Allows Limit() without Order() with MSSQL as per https://stackoverflow.com/a/36156953
if q.limit > 0 && fmter.Dialect().Features().Has(feature.OffsetFetch) && len(q.order) == 0 {
b = append(b, "0 AS _temp_sort, "...)
q.order = []schema.QueryWithArgs{schema.UnsafeIdent("_temp_sort")}
}
b, err = q.appendColumns(fmter, b)
if err != nil {
return nil, err
Expand Down

0 comments on commit d566c86

Please sign in to comment.